Skip to content

Commit

Permalink
Merge pull request #22 from testiumjs/mixin-require
Browse files Browse the repository at this point in the history
fix: support `mixins.wd[] = 'some-module'`
  • Loading branch information
dbushong authored Jul 22, 2017
2 parents af26f7e + 97ca84f commit e70ebb3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .testiumrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"command": "testium-example-app"
},
"mixins": {
"wd": [ "test/mixin.js" ]
"wd": [ "test/mixin.js", "test-mixin-module" ]
}
}
20 changes: 18 additions & 2 deletions lib/testium-driver-wd.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,24 @@ function applyMethods(methods) {

function applyMixin(mixin) {
debug('Applying mixin to wd', mixin);
var mixinFile = path.resolve(process.cwd(), mixin);
applyMethods(require(mixinFile)); // eslint-disable-line global-require
// this is all to be bug-compatible with our old implementation, which
// would parse a mixin path of "test/blah" the same as "./test/blah"
var cwd = process.cwd();
var paths = [path.resolve(cwd, mixin), path.resolve(cwd, 'node_modules', mixin)];
var mixins;
_.forEach(paths, function eachFile(mixinFile) {
try {
mixins = require(mixinFile); // eslint-disable-line global-require
return false;
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') throw err;
return undefined;
}
});
if (!mixins) {
throw new Error('couldn\'t find ' + mixin + ' in ' + paths.join(' or '));
}
applyMethods(mixins);
}

function initDriver(testium) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"eslint-config-groupon": "^3.2.0",
"eslint-config-groupon-es5": "^3.0.0",
"eslint-plugin-import": "^1.6.1",
"test-mixin-module": "file:./test/test-mixin-module",
"mocha": "^3.1.2",
"nlm": "^3.0.0",
"testium-core": "^1.3.0",
Expand Down
6 changes: 5 additions & 1 deletion test/integration/mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import assert from 'assertive';
describe('mixin', () => {
before(browser.beforeHook);

it('exposes the mixed-in method', async () => {
it('exposes the relative path mixed-in method', async () => {
assert.equal(10, await browser.mixedInMethod());
});

it('exposes the external module mixed-in method', async () => {
assert.equal(42, await browser.anotherMethod());
});
});
3 changes: 3 additions & 0 deletions test/test-mixin-module/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.anotherMethod = function anotherMethod() {
return 42;
};
5 changes: 5 additions & 0 deletions test/test-mixin-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "test-mixin-module",
"version": "0.0.0",
"description": "Mixin Fake Test Module"
}

0 comments on commit e70ebb3

Please sign in to comment.