Repository: Codeception/CodeceptJS
Pull request #482 (2017-04-20 08:36:42)

Fixed run-multiple 
* define output directory for each browser configuration
* create output directory in run if it doesn't exist:

```
creating output directory: /home/davert/projects/codeceptjs/examples/output/default_browser_firefox_2
creating output directory: /home/davert/projects/codeceptjs/examples/output/default_browser_chrome_1
```

* add suite counter to run multiple to mark different suites in output:

```
[1.default:chrome] CodeceptJS v0.6.1
[2.default:firefox] CodeceptJS v0.6.1
```


Patch:
diff --git a/lib/command/run-multiple.js b/lib/command/run-multiple.js
index 054c2cc2..ecb933dc 100644
--- a/lib/command/run-multiple.js
+++ b/lib/command/run-multiple.js
@@ -17,6 +17,8 @@ const copyOptions = ['steps', 'reporter', 'verbose', 'config', 'reporter-options
 // codeceptjs run:multiple all - will launch all suites
 // codeceptjs run:multiple smoke regression'
 
+let suiteId = 1;
+
 module.exports = function (suites, options) {
   // registering options globally to use in config
   process.profile = options.profile;
@@ -71,7 +73,8 @@ function runSuite(suite, suiteConf, browser) {
     return;
   }
 
-  let overriddenConfig = config;
+  // clone config
+  let overriddenConfig = Object.assign({}, config);
 
   if (suiteBrowsers.indexOf(browser) === -1) {
     throw new Error(`Browser ${browser} not found in multiple suite "${suite}" config`);
@@ -85,13 +88,15 @@ function runSuite(suite, suiteConf, browser) {
     overriddenConfig.helpers = replaceValue(overriddenConfig.helpers, key, browserConfig[key]);
   }
 
+  let outputDir = suite + JSON.stringify(browserConfig).replace(/[^\d\w]+/g, '_') + suiteId;
+
   // tweaking default output directories and for mochawesome
-  overriddenConfig = replaceValue(overriddenConfig, 'output', `${config.output}/${suite}_${browser}/`);
-  overriddenConfig = replaceValue(overriddenConfig, 'reportDir', `${config.output}/${suite}_${browser}/`);
+  overriddenConfig = replaceValue(overriddenConfig, 'output', path.join(config.output, outputDir));
+  overriddenConfig = replaceValue(overriddenConfig, 'reportDir', path.join(config.output, outputDir));
 
   // override grep param and collect all params
   let params = ['run',
-    '--child', `${suite}:${browser}`,
+    '--child', `${suiteId++}.${suite}:${browser}`,
     '--override', JSON.stringify(overriddenConfig)
   ];
 
diff --git a/lib/command/run.js b/lib/command/run.js
index edc16125..2e56a54d 100644
--- a/lib/command/run.js
+++ b/lib/command/run.js
@@ -1,15 +1,19 @@
 'use strict';
-let getConfig = require('./utils').getConfig;
-let getTestRoot = require('./utils').getTestRoot;
-let deepMerge = require('./utils').deepMerge;
-let Codecept = require('../codecept');
-let Config = require('../config');
+const getConfig = require('./utils').getConfig;
+const getTestRoot = require('./utils').getTestRoot;
+const deepMerge = require('./utils').deepMerge;
+const fileExists = require('../utils').fileExists;
+const path = require('path');
+const fs = require('fs');
+const Config = require('../config');
+const Codecept = require('../codecept');
+const output = require('../output');
 
 module.exports = function (test, options) {
   // registering options globally to use in config
   process.profile = options.profile;
   let configFile = options.config;
-  let codecept;
+  let codecept, outputDir;
 
   let testRoot = getTestRoot(configFile);
   let config = getConfig(configFile);
@@ -17,6 +21,11 @@ module.exports = function (test, options) {
     config = Config.append(JSON.parse(options.override));
   }
 
+  if (!fileExists(outputDir = path.join(testRoot, config.output))) {
+    output.print('creating output directory: ' + outputDir);
+    fs.mkdirSync(outputDir);
+  }
+
   try {
     codecept = new Codecept(config, options);
     codecept.init(testRoot, function (err) {


Test patch:
diff --git a/test/runner/codecept_test.js b/test/runner/codecept_test.js
index 86eb2184..b8eb398b 100644
--- a/test/runner/codecept_test.js
+++ b/test/runner/codecept_test.js
@@ -96,7 +96,6 @@ describe('CodeceptJS Runner', () => {
   });
 
   it('should run dynamic config', (done) => {
-    console.log(codecept_run_config('config.js'));
     exec(codecept_run_config('config.js'), (err, stdout, stderr) => {
       stdout.should.include('Filesystem'); // feature
       assert(!err);
diff --git a/test/runner/run_multiple_test.js b/test/runner/run_multiple_test.js
index 27afc857..c2bd3f29 100644
--- a/test/runner/run_multiple_test.js
+++ b/test/runner/run_multiple_test.js
@@ -19,8 +19,8 @@ describe('CodeceptJS Multiple Runner', function() {
   it('should execute one suite with browser', (done) => {
     exec(codecept_run+'default:firefox', (err, stdout, stderr) => {
       stdout.should.include('CodeceptJS'); // feature
-      stdout.should.include('[default:firefox] print browser ');
-      stdout.should.not.include('[default:chrome] print browser ');
+      stdout.should.include('.default:firefox] print browser ');
+      stdout.should.not.include('.default:chrome] print browser ');
       assert(!err);
       done();
     });
@@ -29,8 +29,8 @@ describe('CodeceptJS Multiple Runner', function() {
   it('should execute one suite with browser', (done) => {
     exec(codecept_run+'default:firefox', (err, stdout, stderr) => {
       stdout.should.include('CodeceptJS'); // feature
-      stdout.should.include('[default:firefox] print browser ');
-      stdout.should.not.include('[default:chrome] print browser ');
+      stdout.should.include('.default:firefox] print browser ');
+      stdout.should.not.include('.default:chrome] print browser ');
       assert(!err);
       done();
     });
@@ -39,22 +39,22 @@ describe('CodeceptJS Multiple Runner', function() {
   it('should execute all suites', (done) => {
     exec(codecept_run+'--all', (err, stdout, stderr) => {
       stdout.should.include('CodeceptJS'); // feature
-      stdout.should.include('[default:firefox] print browser ');
-      stdout.should.include('[default:chrome] print browser ');
-      stdout.should.include('[mobile:safari] print browser ');
-      stdout.should.include('[mobile:android] print browser ');
+      stdout.should.include('[1.default:chrome] print browser ');
+      stdout.should.include('[2.default:firefox] print browser ');
+      stdout.should.include('[3.mobile:android] print browser ');
+      stdout.should.include('[4.mobile:safari] print browser ');
       assert(!err);
       done();
     });
   });
 
-  it('should execute mutiple suites', (done) => {
-    exec(codecept_run+'default mobile', (err, stdout, stderr) => {
+  it('should execute multiple suites', (done) => {
+    exec(codecept_run+'mobile default ', (err, stdout, stderr) => {
       stdout.should.include('CodeceptJS'); // feature
-      stdout.should.include('[default:firefox] print browser ');
-      stdout.should.include('[default:chrome] print browser ');
-      stdout.should.include('[mobile:safari] print browser ');
-      stdout.should.include('[mobile:android] print browser ');
+      stdout.should.include('[1.mobile:android] print browser ');
+      stdout.should.include('[2.mobile:safari] print browser ');
+      stdout.should.include('[3.default:chrome] print browser ');
+      stdout.should.include('[4.default:firefox] print browser ');
       assert(!err);
       done();
     });
@@ -63,15 +63,13 @@ describe('CodeceptJS Multiple Runner', function() {
   it('should print steps', (done) => {
     exec(codecept_run+'default --steps', (err, stdout, stderr) => {
       stdout.should.include('CodeceptJS'); // feature
-      stdout.should.include('[default:firefox] print browser ');
-      stdout.should.include('[default:firefox]  • I print browser');
-      stdout.should.include('[default:chrome] print browser ');
-      stdout.should.include('[default:chrome]  • I print browser');
+      stdout.should.include('[2.default:firefox] print browser ');
+      stdout.should.include('[2.default:firefox]  • I print browser');
+      stdout.should.include('[1.default:chrome] print browser ');
+      stdout.should.include('[1.default:chrome]  • I print browser');
       assert(!err);
       done();
     });
   });
 
-
-
 });
\ No newline at end of file