Repository: Codeception/CodeceptJS
Pull request #982 (2018-03-03 05:53:48)

[feature] Enable glob patterns in `config.test` / `Codecept.loadTests`
See #976 

codacy-bot: 
![Codacy](https://app.codacy.com/assets/images/favicon.png) Here is an overview of what got changed by this pull request:


```diff

Issues
======
- Added 3
           
```


See the complete overview on [Codacy](https://app.codacy.com/app/DavertMik/CodeceptJS/pullRequest?prid=1392320&bid=6688799)
        
reubenmiller: Great work :) Though can you please fix the linting issues because it is causing the ci tests to fail.
codacy-bot: 
![Codacy](https://app.codacy.com/assets/images/favicon.png) Here is an overview of what got changed by this pull request:


```diff

Issues
======
- Added 1
           
```


See the complete overview on [Codacy](https://app.codacy.com/app/DavertMik/CodeceptJS/pullRequest?prid=1392320&bid=6688799)
        
codacy-bot: 
![Codacy](https://app.codacy.com/assets/images/favicon.png) Here is an overview of what got changed by this pull request:


```diff

Issues
======
- Added 1
           
```


See the complete overview on [Codacy](https://app.codacy.com/app/DavertMik/CodeceptJS/pullRequest?prid=1392320&bid=6688799)
        
codacy-bot: 
![Codacy](https://app.codacy.com/assets/images/favicon.png) Here is an overview of what got changed by this pull request:


```diff

Issues
======
- Added 1
           
```


See the complete overview on [Codacy](https://app.codacy.com/app/DavertMik/CodeceptJS/pullRequest?prid=1392320&bid=6688799)
        
codacy-bot: 
![Codacy](https://app.codacy.com/assets/images/favicon.png) Here is an overview of what got changed by this pull request:


```diff

Issues
======
- Added 1
           
```


See the complete overview on [Codacy](https://app.codacy.com/app/DavertMik/CodeceptJS/pullRequest?prid=1392320&bid=6688799)
        
codacy-bot: 
![Codacy](https://app.codacy.com/assets/images/favicon.png) Here is an overview of what got changed by this pull request:


```diff

Issues
======
- Added 1
           
```


See the complete overview on [Codacy](https://app.codacy.com/app/DavertMik/CodeceptJS/pullRequest?prid=1392320&bid=6688799)
        
sveneisenschmidt: @DavertMik @reubenmiller  `Hound` and `Codacy` seems to have a different opinion here. Any idea how to fix this? I use the default .editorconfig and the file just looks fine.
reubenmiller: @sveneisenschmidt what do you get when you run the linting locally? `npm run lint`. If it fails there then you might be able to use `npm run lint-fix`.

Though it's strange because in the travis tests, it runs `npm run lint` and I've already seen that the tests are passing (so that would suggest the above commands are working fine).
sveneisenschmidt: @reubenmiller Yep, seems all good:

```console
> docker run -i -t --rm -v $PWD:/data:cached -w /data node:9 /bin/bash
root@c981a7f8eb1e:/data# npm install
added 136 packages and updated 1 package in 92.467s

root@c981a7f8eb1e:/data# npm run lint
> codeceptjs@1.1.6 lint /data
> eslint bin/ examples/ lib/ test/ translations/

root@c981a7f8eb1e:/data# npm run lint-fix
> codeceptjs@1.1.6 lint-fix /data
> eslint bin/ examples/ lib/ test/ translations/ --fix

root@c981a7f8eb1e:/data
```

How to proceed now? :)

Patch:
diff --git a/lib/codecept.js b/lib/codecept.js
index 04921c9a..b76b1e71 100644
--- a/lib/codecept.js
+++ b/lib/codecept.js
@@ -85,7 +85,12 @@ class Codecept {
    */
   loadTests(pattern) {
     pattern = pattern || this.config.tests;
-    glob.sync(fsPath.resolve(global.codecept_dir, pattern)).forEach((file) => {
+
+    const options = {
+      cwd: global.codecept_dir,
+    };
+
+    glob.sync(pattern, options).forEach((file) => {
       this.testFiles.push(fsPath.resolve(file));
     });
   }
diff --git a/lib/command/run-multiple.js b/lib/command/run-multiple.js
index e3e922d3..ad18410e 100644
--- a/lib/command/run-multiple.js
+++ b/lib/command/run-multiple.js
@@ -143,6 +143,11 @@ function runSuite(suite, suiteConf, browser) {
   overriddenConfig = replaceValue(overriddenConfig, 'reportDir', path.join(config.output, outputDir));
   overriddenConfig = replaceValue(overriddenConfig, 'mochaFile', path.join(config.output, outputDir, `${browser}_report.xml`));
 
+  // override tests configuration
+  if (overriddenConfig.tests) {
+    overriddenConfig.tests = suiteConf.tests;
+  }
+
   // override grep param and collect all params
   const params = ['run',
     '--child', `${suiteId++}.${suite}:${browser}`,
diff --git a/lib/helper/Nightmare.js b/lib/helper/Nightmare.js
index e2176be4..eb20f630 100644
--- a/lib/helper/Nightmare.js
+++ b/lib/helper/Nightmare.js
@@ -865,7 +865,7 @@ class Nightmare extends Helper {
   }
 
   /**
-   * {{> ../webapi/waitForVisible }}
+   * {{> ../webapi/waitForInvisible }}
    */
   waitForInvisible(locator, sec) {
     this.browser.options.waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout;


Test patch:
diff --git a/test/data/sandbox/codecept.glob.json b/test/data/sandbox/codecept.glob.json
new file mode 100644
index 00000000..76756f38
--- /dev/null
+++ b/test/data/sandbox/codecept.glob.json
@@ -0,0 +1,12 @@
+{
+  "tests": "{./*does_not_exist_test.js,./*fs_test.glob.js}",
+  "timeout": 10000,
+  "output": "./output",
+  "helpers": {
+    "FileSystem": {}
+  },
+  "include": {},
+  "bootstrap": false,
+  "mocha": {},
+  "name": "sandbox"
+}
\ No newline at end of file
diff --git a/test/data/sandbox/codecept.multiple.json b/test/data/sandbox/codecept.multiple.json
index 918d9cff..5adf5841 100644
--- a/test/data/sandbox/codecept.multiple.json
+++ b/test/data/sandbox/codecept.multiple.json
@@ -25,6 +25,11 @@
       "grep": "@grep",
       "browsers": ["chrome",
         { "browser": "firefox", "windowSize": "1200x840"}]
+    },
+    "test": {
+      "tests": "./*_test_override.multiple.js",
+      "browsers": ["chrome",
+        { "browser": "firefox", "windowSize": "1200x840"}]
     }
   },
   "include": {},
diff --git a/test/data/sandbox/fs_test.glob.js b/test/data/sandbox/fs_test.glob.js
new file mode 100644
index 00000000..bb652540
--- /dev/null
+++ b/test/data/sandbox/fs_test.glob.js
@@ -0,0 +1,7 @@
+Feature('Filesystem');
+
+Scenario('glob current dir', (I) => {
+  I.amInPath('.');
+  I.say('hello world');
+  I.seeFile('codecept.glob.json');
+});
diff --git a/test/data/sandbox/tests_test_override.multiple.js b/test/data/sandbox/tests_test_override.multiple.js
new file mode 100644
index 00000000..d8cb6c27
--- /dev/null
+++ b/test/data/sandbox/tests_test_override.multiple.js
@@ -0,0 +1,5 @@
+Feature('print browser size');
+
+Scenario('print browser size info', (I) => {
+  I.printWindowSize();
+});
diff --git a/test/docker-compose.yml b/test/docker-compose.yml
index 5d9399a2..4c4a71d9 100644
--- a/test/docker-compose.yml
+++ b/test/docker-compose.yml
@@ -9,6 +9,15 @@ services:
       - ..:/codecept
       - node_modules:/codecept/node_modules
 
+  test-runner:
+    build: ..
+    entrypoint: docker/entrypoint node_modules/.bin/mocha
+    command: test/runner
+    working_dir: /codecept
+    volumes:
+      - ..:/codecept
+      - node_modules:/codecept/node_modules
+
   test-helpers:
     build: ..
     entrypoint: docker/entrypoint node_modules/.bin/mocha --invert --fgrep Appium
diff --git a/test/runner/codecept_test.js b/test/runner/codecept_test.js
index 06b9f7d5..8a12c280 100644
--- a/test/runner/codecept_test.js
+++ b/test/runner/codecept_test.js
@@ -26,6 +26,15 @@ describe('CodeceptJS Runner', () => {
     });
   });
 
+  it('should be executed with glob', (done) => {
+    process.chdir(codecept_dir);
+    exec(codecept_run_config('codecept.glob.json'), (err, stdout, stderr) => {
+      stdout.should.include('Filesystem'); // feature
+      stdout.should.include('glob current dir'); // test name
+      assert(!err);
+      done();
+    });
+  });
 
   it('should be executed with config path', (done) => {
     exec(`${codecept_run} -c ${codecept_dir}`, (err, stdout, stderr) => {
diff --git a/test/runner/run_multiple_test.js b/test/runner/run_multiple_test.js
index 9ffe9fad..65704b99 100644
--- a/test/runner/run_multiple_test.js
+++ b/test/runner/run_multiple_test.js
@@ -101,4 +101,16 @@ describe('CodeceptJS Multiple Runner', function () {
       done();
     });
   });
+
+  it('should pass tests to configuration', (done) => {
+    exec(`${codecept_run}test`, (err, stdout, stderr) => {
+      stdout.should.include('CodeceptJS'); // feature
+      stdout.should.include('[1.test:chrome] print browser size');
+      stdout.should.include('[2.test:firefox] print browser size');
+      stdout.should.include('[1.test:chrome] print browser ');
+      stdout.should.include('[2.test:firefox] print browser ');
+      assert(!err);
+      done();
+    });
+  });
 });