Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from TestArmada/mocha
Browse files Browse the repository at this point in the history
add support for mocha
  • Loading branch information
archlichking authored Apr 25, 2017
2 parents ae0367f + a671059 commit f5cdd58
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 141 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please follow the steps
]
```

3. `./node_modules/.bin/magellan ----help` to see if you can see the following content printed out
3. `./node_modules/.bin/magellan --help` to see if you can see the following content printed out
```
Executor-specific (testarmada-magellan-local-executor)
--local_browser=browsername Run tests in chrome, firefox, etc (default: phantomjs).
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testarmada-magellan-local-executor",
"version": "1.0.0",
"version": "1.1.0",
"description": "test executor for magellan test to run in local selenium env",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -34,6 +34,7 @@
"babel-preset-es2015": "^6.18.0",
"cli-color": "^1.1.0",
"lodash": "^4.17.4",
"testarmada-logger": "^1.1.1",
"yargs": "^6.6.0"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions src/help.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export default {
"local_mocha": {
"visible": true,
"type": "boolean",
"description": "Run test via magellan-mocha-plugin "
+ "(exclusive with list_browser and list_browsers)"
},
"local_browser": {
"visible": true,
"type": "string",
Expand Down
38 changes: 0 additions & 38 deletions src/logger.js

This file was deleted.

163 changes: 92 additions & 71 deletions src/profile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from "path";
import _ from "lodash";
import { argv } from "yargs";
import logger from "./logger";
import logger from "testarmada-logger";
logger.prefix = "Local Executor";

export default {
getNightwatchConfig: (profile) => {
Expand All @@ -19,93 +20,113 @@ export default {
if (argvMock) {
runArgv = argvMock;
}
if (runArgv.local_mocha
|| opts.settings.testFramework.name
&& opts.settings.testFramework.name === "testarmada-magellan-mocha-plugin") {
// do nothing for mocha
return new Promise((resolve) => resolve([{ executor: "local", id: "mocha" }]));
} else {
const configPath = opts.settings.testFramework.settings.nightwatchConfigFilePath;

/*eslint-disable global-require*/
const nightwatchConfig = require(path.resolve(configPath));
const browsers = nightwatchConfig.test_settings;

return new Promise((resolve) => {
if (runArgv.local_browser) {
const localBrowser = runArgv.local_browser;
if (browsers[localBrowser]) {
const b = browsers[localBrowser];

const configPath = opts.settings.testFramework.settings.nightwatchConfigFilePath;

/*eslint-disable global-require*/
const nightwatchConfig = require(path.resolve(configPath));
const browsers = nightwatchConfig.test_settings;

return new Promise((resolve) => {
if (runArgv.local_browser) {
const localBrowser = runArgv.local_browser;
if (browsers[localBrowser]) {
const b = browsers[localBrowser];

b.executor = "local";
b.nightwatchEnv = localBrowser;
b.id = localBrowser;
b.executor = "local";
b.nightwatchEnv = localBrowser;
b.id = localBrowser;

logger.debug(`detected profile: ${ JSON.stringify(b)}`);
logger.debug(`detected profile: ${JSON.stringify(b)}`);

resolve([b]);
}
} else if (runArgv.local_browsers) {
const tempBrowsers = runArgv.local_browsers.split(",");
const returnBrowsers = [];
resolve([b]);
}
} else if (runArgv.local_browsers) {
const tempBrowsers = runArgv.local_browsers.split(",");
const returnBrowsers = [];

_.forEach(tempBrowsers, (browser) => {
if (browsers[browser]) {
const b = browsers[browser];
_.forEach(tempBrowsers, (browser) => {
if (browsers[browser]) {
const b = browsers[browser];

b.executor = "local";
b.nightwatchEnv = browser;
b.id = browser;
b.executor = "local";
b.nightwatchEnv = browser;
b.id = browser;

returnBrowsers.push(b);
}
});
returnBrowsers.push(b);
}
});

logger.debug(`detected profiles: ${ JSON.stringify(returnBrowsers)}`);
logger.debug(`detected profiles: ${JSON.stringify(returnBrowsers)}`);

resolve(returnBrowsers);
} else {
resolve();
}
});
resolve(returnBrowsers);
} else {
resolve();
}
});
}
},

/*eslint-disable global-require*/
getCapabilities: (profile, opts) => {
const configPath = opts.settings.testFramework.settings.nightwatchConfigFilePath;
const nightwatchConfig = require(path.resolve(configPath));
const browsers = nightwatchConfig.test_settings;

return new Promise((resolve, reject) => {
if (browsers[profile]) {
const b = browsers[profile];

b.executor = "local";
b.nightwatchEnv = profile;
b.id = profile;

resolve(b);
} else {
reject(`profile: ${ profile } isn't found`);
}
});
if (argv.local_mocha
|| opts.settings.testFramework.name
&& opts.settings.testFramework.name === "testarmada-magellan-mocha-plugin") {
// do nothing for mocha
return new Promise((resolve) => resolve({ executor: "local", id: "mocha" }));
} else {
const configPath = opts.settings.testFramework.settings.nightwatchConfigFilePath;
const nightwatchConfig = require(path.resolve(configPath));
const browsers = nightwatchConfig.test_settings;

return new Promise((resolve, reject) => {
if (browsers[profile]) {
const b = browsers[profile];

b.executor = "local";
b.nightwatchEnv = profile;
b.id = profile;

resolve(b);
} else {
reject(`profile: ${profile} isn't found`);
}
});
}
},

/*eslint-disable global-require*/
listBrowsers: (opts, callback) => {
const configPath = opts.settings.testFramework.settings.nightwatchConfigFilePath;
const nightwatchConfig = require(path.resolve(configPath));
const browsers = nightwatchConfig.test_settings;

const OMIT_BROWSERS = ["default", "sauce"];
const listedBrowsers = [];


_.forEach(browsers, (capabilities, browser) => {
if (OMIT_BROWSERS.indexOf(browser) < 0) {
logger.debug(` browser: ${ browser}`);
logger.debug(` capabilities: ${ JSON.stringify(capabilities)}`);
listedBrowsers.push(browser);
}
});
if (argv.local_mocha
|| opts.settings.testFramework.name
&& opts.settings.testFramework.name === "testarmada-magellan-mocha-plugin") {
// do nothing for mocha
return callback();
} else {
const configPath = opts.settings.testFramework.settings.nightwatchConfigFilePath;
const nightwatchConfig = require(path.resolve(configPath));
const browsers = nightwatchConfig.test_settings;

const OMIT_BROWSERS = ["default", "sauce"];
const listedBrowsers = [];


_.forEach(browsers, (capabilities, browser) => {
if (OMIT_BROWSERS.indexOf(browser) < 0) {
logger.debug(` browser: ${browser}`);
logger.debug(` capabilities: ${JSON.stringify(capabilities)}`);
listedBrowsers.push(browser);
}
});

logger.log(`Available browsers from file ${ configPath }: ${ listedBrowsers.join(",")}`);
logger.log(`Available browsers from file ${configPath}: ${listedBrowsers.join(",")}`);

callback();
return callback();
}
}
};
10 changes: 0 additions & 10 deletions test/src/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import chai from "chai";
import chaiAsPromise from "chai-as-promised";
import _ from "lodash";

import logger from "../../lib/logger";

// eat console logs
// logger.output = {
// log() { },
// error() { },
// debug() { },
// warn() { }
// };

chai.use(chaiAsPromise);

const expect = chai.expect;
Expand Down
13 changes: 3 additions & 10 deletions test/src/executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import chai from "chai";
import chaiAsPromise from "chai-as-promised";
import _ from "lodash";

import logger from "../../lib/logger";

// eat console logs
// logger.output = {
// log() { },
// error() { },
// debug() { },
// warn() { }
// };

chai.use(chaiAsPromise);

const expect = chai.expect;
Expand Down Expand Up @@ -63,4 +53,7 @@ describe("Executor", () => {
expect(r).to.equal(1);
});

it("summerizeTest", (done) => {
executor.summerizeTest(null, null, () => done());
});
});
Loading

0 comments on commit f5cdd58

Please sign in to comment.