UNPKG

3.38 kBJavaScriptView Raw
1// Load in our dependencies
2// DEV: By using an internal require here, we have verified that we support internal requires
3var assert = require('assert');
4// DEV: By using a `node_modules` require here, we have verified that we support external requires
5void require('js-string-escape');
6// DEV: By using a `./` require here, we have verified that we support relative requires
7// DEV: We are resolving relative to `node_modules/karma/static/context.html` so lots of `../`
8var submodule = require('../../../test/integration-test/test-files/submodule');
9
10// Start our tests
11describe('All `<script src=` Node.js integrations', function () {
12 it('function as expected', function () {
13 // Example: /home/todd/github/karma-electron/node_modules/karma/static/context.html
14 assert(/karma[\/\\]static[\/\\]context\.html$/.test(__filename),
15 'Expected "' + __filename + '" to end with "karma/static/context.html"');
16 // Example: /home/todd/github/karma-electron/node_modules/karma/static
17 assert(/karma[\/\\]static$/.test(__dirname),
18 'Expected "' + __dirname + '" to end with "karma/static"');
19 });
20});
21
22describe('module for `<script src=` based Node.js integrations', function () {
23 describe('in the top level', function () {
24 // DEV: Determined exepctations via `../reference`
25 it('identify as the page itself', function () {
26 // Example: /home/todd/github/karma-electron/node_modules/karma/static/context.html
27 assert(/karma[\/\\]static[\/\\]context\.html$/.test(module.filename),
28 'Expected "' + module.filename + '" to end with "karma/static/context.html"');
29 assert.strictEqual(typeof module.exports, 'object');
30 assert.strictEqual(module.id, '.');
31 assert.strictEqual(submodule.loaded, true);
32 assert.strictEqual(module.parent, null);
33 });
34 });
35
36 describe('in a child module', function () {
37 // DEV: Determined exepctations via `../reference`
38 it('identify as a standalone module', function () {
39 assert(/test[\/\\]integration-test[\/\\]test-files[\/\\]submodule\.js$/.test(submodule.filename),
40 'Expected "' + submodule.filename + '" to end with "test/integration-test/test-files/submodule.js"');
41 // Verify `hello` property of `module.exports`
42 assert.strictEqual(submodule.exports.hello, 'world');
43 assert(/test[\/\\]integration-test[\/\\]test-files[\/\\]submodule\.js$/.test(submodule.id),
44 'Expected "' + submodule.id + '" to end with "test/integration-test/test-files/submodule.js"');
45 assert.strictEqual(submodule.loaded, true);
46 assert.strictEqual(submodule.parent, module);
47
48 // Verify exported values
49 assert.strictEqual(submodule.hello, 'world');
50 // Example: /home/todd/github/karma-electron/test/integration-test/node-test.js
51 assert(/test[\/\\]integration-test[\/\\]test-files[\/\\]submodule\.js$/.test(submodule.filename),
52 'Expected "' + submodule.filename + '" to end with "test/integration-test/test-files/submodule.js"');
53 // Example: /home/todd/github/karma-electron/test/integration-test
54 assert(/test[\/\\]integration-test[\/\\]test-files$/.test(submodule.dirname),
55 'Expected "' + submodule.dirname + '" to end with "test/integration-test/test-files"');
56 });
57
58 it('has same window context as parent', function () {
59 assert.strictEqual(submodule.before, window.before);
60 });
61 });
62});