Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add tests for ES2015 module support #2834

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion static/context.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
</script>
<!-- Dynamically replaced with <script> tags -->
%SCRIPTS%
<script type="text/javascript">
<!-- Since %SCRIPTS% might include modules, the `loaded()` call needs to be in a module too.
This ensures all the tests will have been declared before karma tries to run them. -->
<script type="module">
window.__karma__.loaded();
</script>
<script nomodule>
window.__karma__.loaded();
</script>
</body>
Expand Down
7 changes: 6 additions & 1 deletion static/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
</script>
<!-- Dynamically replaced with <script> tags -->
%SCRIPTS%
<script type="text/javascript">
<!-- Since %SCRIPTS% might include modules, the `loaded()` call needs to be in a module too.
This ensures all the tests will have been declared before karma tries to run them. -->
<script type="module">
window.__karma__.loaded();
</script>
<script nomodule>
window.__karma__.loaded();
</script>
</body>
Expand Down
35 changes: 35 additions & 0 deletions test/e2e/module-types.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: ES Modules
In order to use Karma
As a person who wants to write great tests
I want to use different script types with Karma.

Scenario: Globbing modules, with both .js and .mjs extensions
Given a configuration with:
"""
files = [
{ pattern: 'modules/**/*.js', type: 'module' },
{ pattern: 'modules/**/*.mjs', type: 'module' },
];
// Chrome fails on Travis, so we must use Firefox (which means we must
// manually enable modules).
customLaunchers = {
FirefoxWithModules: {
base: 'Firefox',
prefs: {
'dom.moduleScripts.enabled': true
}
}
};
browsers = ['FirefoxWithModules'];
frameworks = ['mocha', 'chai'];
plugins = [
'karma-mocha',
'karma-chai',
'karma-firefox-launcher'
];
"""
When I start Karma
Then it passes with like:
"""
Executed 4 of 4 SUCCESS
"""
11 changes: 11 additions & 0 deletions test/e2e/support/modules/__tests__/minus.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { minus } from '../minus.mjs'

describe('minus', function () {
it('should pass', function () {
expect(true).to.be.true
})

it('should work', function () {
expect(minus(3, 2)).to.equal(1)
})
})
11 changes: 11 additions & 0 deletions test/e2e/support/modules/__tests__/plus.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { plus } from '../plus.js'

describe('plus', function () {
it('should pass', function () {
expect(true).to.be.true
})

it('should work', function () {
expect(plus(1, 2)).to.equal(3)
})
})
4 changes: 4 additions & 0 deletions test/e2e/support/modules/minus.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Some code under test
export function minus (a, b) {
return a - b
}
4 changes: 4 additions & 0 deletions test/e2e/support/modules/plus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Some code under test
export function plus (a, b) {
return a + b
}