Skip to content

Commit

Permalink
wrap mocha imports in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thoov committed Feb 16, 2021
1 parent ce00fce commit a70f8e8
Show file tree
Hide file tree
Showing 10 changed files with 567 additions and 513 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
- embroider-safe-with-mocha
- embroider-optimized
- embroider-optimized-with-mocha
- ember-lts-3.24
- ember-lts-3.20
- ember-lts-3.16
- ember-lts-3.12
Expand Down
16 changes: 16 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ module.exports = async function() {
}
}
},
{
name: 'ember-lts-3.20',
npm: {
devDependencies: {
'ember-source': '~3.20.0'
}
}
},
{
name: 'ember-lts-3.24',
npm: {
devDependencies: {
'ember-source': '~3.24.0'
}
}
},
{
name: 'ember-release',
npm: {
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ module.exports = {
.lt('5.0.0-beta.1');

let options = {
exclude: ['ember-mocha', 'mocha']
exclude: ['ember-mocha', 'mocha'],
webpack: {
externals: {
mocha: 'mocha'
},
node: {
stream: false
}
}
};

// Ember-qunit < 5 provides an AMD shim for qunit but newer versions now use
Expand Down
289 changes: 147 additions & 142 deletions tests/unit/mocha/filter-test-modules-test.js
Original file line number Diff line number Diff line change
@@ -1,147 +1,152 @@
import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';
import { convertFilePathToModulePath, filterTestModules } from 'ember-exam/test-support/-private/filter-test-modules';
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';

describe('Unit | Mocha | filter-test-modules', () => {
describe('convertFilePathToModulePath', () => {
it('should return an input string without file extension when the input contains file extension', () => {
expect(convertFilePathToModulePath('/tests/integration/foo.js')).to.equal(
'/tests/integration/foo'
);
});

it(`should return an input string without file extension when the input doesn't contain file extension`, () => {
expect(convertFilePathToModulePath('/tests/integration/foo')).to.equal(
'/tests/integration/foo'
);
});

it('should return an input string after `tests` when the input is a full test file path', () => {
expect(convertFilePathToModulePath('dummy/tests/integration/foo.js')).to.equal(
'/tests/integration/foo'
);
});
});

describe('modulePath | Mocha', () => {
let modules = [];

beforeEach(() => {
modules = [
'foo-test',
'foo-test.jshint',
'bar-test',
'bar-test.jshint',
];
});

afterEach(() => {
modules = [];
});

it('should return a list of jshint tests', () => {
expect(filterTestModules(modules, 'jshint')).to.deep.equal([
'foo-test.jshint',
'bar-test.jshint'
]);
});

it('should return an empty list when there is no match', () => {
expect(() => {
filterTestModules(modules, 'no-match');
}).to.throw(/No tests matched with the filter:/);
});

it('should return a list of tests matched with a regular expression', () => {
expect(filterTestModules(modules, '/jshint/')).to.deep.equal([
'foo-test.jshint',
'bar-test.jshint'
]);
});

it('should return a list of tests matched with a regular expression that excluses jshint', () => {
expect(filterTestModules(modules, '!/jshint/')).to.deep.equal([
'foo-test',
'bar-test'
]);
});

it('should return a list of tests matches with a list of string options', () => {
expect(filterTestModules(modules, 'foo, bar')).to.deep.equal([
'foo-test',
'foo-test.jshint',
'bar-test',
'bar-test.jshint'
]);
});

it('should return a list of unique tests matches when options are repeated', () => {
expect(filterTestModules(modules, 'foo, foo')).to.deep.equal([
'foo-test',
'foo-test.jshint'
]);
if (macroCondition(dependencySatisfies('ember-mocha', '*'))) {
let { describe, it, beforeEach, afterEach } = importSync('mocha');
let { expect } = importSync('chai');

describe('Unit | Mocha | filter-test-modules', () => {
describe('convertFilePathToModulePath', () => {
it('should return an input string without file extension when the input contains file extension', () => {
expect(convertFilePathToModulePath('/tests/integration/foo.js')).to.equal(
'/tests/integration/foo'
);
});

it(`should return an input string without file extension when the input doesn't contain file extension`, () => {
expect(convertFilePathToModulePath('/tests/integration/foo')).to.equal(
'/tests/integration/foo'
);
});

it('should return an input string after `tests` when the input is a full test file path', () => {
expect(convertFilePathToModulePath('dummy/tests/integration/foo.js')).to.equal(
'/tests/integration/foo'
);
});
});

describe('modulePath | Mocha', () => {
let modules = [];

beforeEach(() => {
modules = [
'foo-test',
'foo-test.jshint',
'bar-test',
'bar-test.jshint',
];
});

afterEach(() => {
modules = [];
});

it('should return a list of jshint tests', () => {
expect(filterTestModules(modules, 'jshint')).to.deep.equal([
'foo-test.jshint',
'bar-test.jshint'
]);
});

it('should return an empty list when there is no match', () => {
expect(() => {
filterTestModules(modules, 'no-match');
}).to.throw(/No tests matched with the filter:/);
});

it('should return a list of tests matched with a regular expression', () => {
expect(filterTestModules(modules, '/jshint/')).to.deep.equal([
'foo-test.jshint',
'bar-test.jshint'
]);
});

it('should return a list of tests matched with a regular expression that excluses jshint', () => {
expect(filterTestModules(modules, '!/jshint/')).to.deep.equal([
'foo-test',
'bar-test'
]);
});

it('should return a list of tests matches with a list of string options', () => {
expect(filterTestModules(modules, 'foo, bar')).to.deep.equal([
'foo-test',
'foo-test.jshint',
'bar-test',
'bar-test.jshint'
]);
});

it('should return a list of unique tests matches when options are repeated', () => {
expect(filterTestModules(modules, 'foo, foo')).to.deep.equal([
'foo-test',
'foo-test.jshint'
]);
});
});

describe('filePath | Mocha', () => {
let modules = [];

beforeEach(() => {
modules = [
'dummy/tests/integration/foo-test',
'dummy/tests/unit/foo-test',
'dummy/tests/unit/bar-test'
];
});

afterEach(() => {
modules = [];
});

it('should return a test module matches with full test file path', () => {
expect(filterTestModules(modules, null, 'app/tests/integration/foo-test.js')).to.deep.equal([
'dummy/tests/integration/foo-test'
]);
});

it('should return a test module matches with relative test file path', () => {
expect(filterTestModules(modules, null, '/tests/unit/foo-test')).to.deep.equal([
'dummy/tests/unit/foo-test'
]);
});

it('should return a test module matched with test file path with wildcard', () => {
expect(filterTestModules(modules, null, '/unit/*')).to.deep.equal([
'dummy/tests/unit/foo-test',
'dummy/tests/unit/bar-test'
]);
});

it('should return a test module matched with test file path with wildcard', () => {
expect(filterTestModules(modules, null, '/tests/*/foo*')).to.deep.equal([
'dummy/tests/integration/foo-test',
'dummy/tests/unit/foo-test'
]);
});

it('should return a list of tests matched with a regular expression', () => {
expect(() => {
filterTestModules(modules, null, 'no-match');
}).to.throw(/No tests matched with the filter:/);
});

it('should return a list of tests matches with a list of string options', () => {
expect(filterTestModules(modules, null, '/tests/integration/*, dummy/tests/unit/foo-test')).to.deep.equal([
'dummy/tests/integration/foo-test',
'dummy/tests/unit/foo-test'
]);
});

it('should return a list of unique tests matches when options are repeated', () => {
expect(filterTestModules(modules, null, 'app/tests/unit/bar-test.js, /tests/unit/*')).to.deep.equal([
'dummy/tests/unit/bar-test',
'dummy/tests/unit/foo-test'
]);
});
});
});
}

describe('filePath | Mocha', () => {
let modules = [];

beforeEach(() => {
modules = [
'dummy/tests/integration/foo-test',
'dummy/tests/unit/foo-test',
'dummy/tests/unit/bar-test'
];
});

afterEach(() => {
modules = [];
});

it('should return a test module matches with full test file path', () => {
expect(filterTestModules(modules, null, 'app/tests/integration/foo-test.js')).to.deep.equal([
'dummy/tests/integration/foo-test'
]);
});

it('should return a test module matches with relative test file path', () => {
expect(filterTestModules(modules, null, '/tests/unit/foo-test')).to.deep.equal([
'dummy/tests/unit/foo-test'
]);
});

it('should return a test module matched with test file path with wildcard', () => {
expect(filterTestModules(modules, null, '/unit/*')).to.deep.equal([
'dummy/tests/unit/foo-test',
'dummy/tests/unit/bar-test'
]);
});

it('should return a test module matched with test file path with wildcard', () => {
expect(filterTestModules(modules, null, '/tests/*/foo*')).to.deep.equal([
'dummy/tests/integration/foo-test',
'dummy/tests/unit/foo-test'
]);
});

it('should return a list of tests matched with a regular expression', () => {
expect(() => {
filterTestModules(modules, null, 'no-match');
}).to.throw(/No tests matched with the filter:/);
});

it('should return a list of tests matches with a list of string options', () => {
expect(filterTestModules(modules, null, '/tests/integration/*, dummy/tests/unit/foo-test')).to.deep.equal([
'dummy/tests/integration/foo-test',
'dummy/tests/unit/foo-test'
]);
});

it('should return a list of unique tests matches when options are repeated', () => {
expect(filterTestModules(modules, null, 'app/tests/unit/bar-test.js, /tests/unit/*')).to.deep.equal([
'dummy/tests/unit/bar-test',
'dummy/tests/unit/foo-test'
]);
});
});
});
16 changes: 10 additions & 6 deletions tests/unit/mocha/multiple-edge-cases-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';

describe('Mocha | #3: Module With Multiple Edge Case Tests', function() {
it('#1 RegExp test', function() {
expect(/derp/.test('derp')).to.be.ok;
if (macroCondition(dependencySatisfies('ember-mocha', '*'))) {
let { describe, it } = importSync('mocha');
let { expect } = importSync('chai');

describe('Mocha | #3: Module With Multiple Edge Case Tests', function() {
it('#1 RegExp test', function() {
expect(/derp/.test('derp')).to.be.ok;
});
});
});
}
Loading

0 comments on commit a70f8e8

Please sign in to comment.