Codeceptjs: Recursively check subfolders of the test input pattern

Created on 15 Sep 2017  路  3Comments  路  Source: codeceptjs/CodeceptJS

What I want

I want a test features folder that contains both files adjacent to folders that also contain files

E.g.

features/
  |- a.test.js
  |- a-folder/
    |-a.nother.test.js

What I get

To the best of my knowledge, currently I can only have adjacent files or a single linear folder hierarchy

E.g.

features/
  |- a-folder/
    |-a.test.js

or

features/
  |- a.test.js
  |- b.test.js
  |- c.test.js

What happens

The tests are currently loaded form the pattern options, called 'tests'. This is the section of code that globs the pattern and adds each file path it finds to a list of file paths to be loaded
https://github.com/Codeception/CodeceptJS/blob/master/lib/codecept.js#L94-L99
tl;dr? Don;t worry, this is what it looks like

 loadTests(pattern) {
    pattern = pattern || this.config.tests;
    glob.sync(fsPath.resolve(global.codecept_dir, pattern)).forEach((file) => {
      this.testFiles.push(fsPath.resolve(file));
    });
  }

And...
....this is what I propose

loadTests(pattern) {
  pattern = pattern || this.config.tests;
  glob.sync(fsPath.resolve(global.codecept_dir, pattern)).forEach((file) => {
    if (fs.lstatSync(file).isDirectory()) {
      loadTests(fsPath.resolve(global.codecept_dir, `${pattern}/*`));
    } else {
      this.testFiles.push(fsPath.resolve(file));
    }
  });
}

^ Check if the value is a folder, if so resolves the path and recurse through the loadTests method until it reaches a file, then add that file path to the list of file paths to be loaded

question

Most helpful comment

@JoeChapman ./tests/**/*_test.js in codecept.json will search tests recurcive in test folder

All 3 comments

@JoeChapman ./tests/**/*_test.js in codecept.json will search tests recurcive in test folder

@APshenkin you are correct, thank you.

Nice very helpful!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ecampii picture ecampii  路  3Comments

DioNNiS picture DioNNiS  路  3Comments

hanthomas picture hanthomas  路  4Comments

javigomez picture javigomez  路  3Comments

DenisChulkov picture DenisChulkov  路  4Comments