How to use this.getSpecFiles method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

specs-store.js

Source: specs-store.js Github

copy
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.SpecsStore = void 0;
4const tslib_1 = require("tslib");
5const chokidar_1 = (0, tslib_1.__importDefault)(require("chokidar"));
6const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
7const specs_1 = (0, tslib_1.__importDefault)(require("./util/specs"));
8// TODO: shouldn't this be on the trailing edge, not leading?
9const debounce = (fn) => lodash_1.default.debounce(fn, 250, { leading: true });
10class SpecsStore {
11    constructor(cypressConfig, runner) {
12        this.cypressConfig = cypressConfig;
13        this.runner = runner;
14        this.watcher = null;
15        this.specFiles = [];
16    }
17    get specDirectory() {
18        if (this.runner === 'e2e') {
19            return this.cypressConfig.resolved.integrationFolder.value;
20        }
21        if (this.runner === 'component') {
22            return this.cypressConfig.resolved.componentFolder.value;
23        }
24    }
25    get testFiles() {
26        return this.cypressConfig.resolved.testFiles.value;
27    }
28    get watchOptions() {
29        return {
30            cwd: this.specDirectory,
31            ignored: this.cypressConfig.ignoreTestFiles,
32            ignoreInitial: true,
33        };
34    }
35    storeSpecFiles() {
36        return this.getSpecFiles()
37            .then((specFiles) => {
38            this.specFiles = specFiles;
39        });
40    }
41    getSpecFiles() {
42        const searchOptions = {
43            projectRoot: this.cypressConfig.projectRoot,
44            fixturesFolder: this.cypressConfig.fixturesFolder,
45            supportFile: this.cypressConfig.supportFile,
46            testFiles: this.cypressConfig.testFiles,
47            ignoreTestFiles: this.cypressConfig.ignoreTestFiles,
48        };
49        searchOptions.testFiles = this.testFiles;
50        return specs_1.default.findSpecsOfType(this.specDirectory, searchOptions);
51    }
52    watch(options) {
53        this.watcher = chokidar_1.default.watch(this.cypressConfig.testFiles, this.watchOptions);
54        const onSpecsChanged = debounce(() => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
55            const newSpecs = yield this.getSpecFiles();
56            if (lodash_1.default.isEqual(newSpecs, this.specFiles))
57                return;
58            this.specFiles = newSpecs;
59            options.onSpecsChanged(newSpecs);
60        }));
61        this.watcher.on('add', onSpecsChanged);
62        this.watcher.on('unlink', onSpecsChanged);
63    }
64    reset() {
65        var _a;
66        (_a = this.watcher) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
67    }
68}
69exports.SpecsStore = SpecsStore;
70
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cypress on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)