UNPKG

4.01 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
7var submodule = require('./test-files/submodule');
8
9// Start our tests
10describe('All `require` based Node.js integrations', function () {
11 it('function as expected', function () {
12 // Example: /home/todd/github/karma-electron/test/integration-test/node-require-test.js
13 assert(/test[\/\\]integration-test[\/\\]node-require-test\.js$/.test(__filename),
14 'Expected "' + __filename + '" to end with "test/integration-test/node-require-test.js"');
15 // Example: /home/todd/github/karma-electron/test/integration-test
16 assert(/test[\/\\]integration-test$/.test(__dirname),
17 'Expected "' + __dirname + '" to end with "test/integration-test"');
18 });
19});
20
21describe('module for `require` based Node.js integrations', function () {
22 describe('in the top level', function () {
23 // DEV: Determined exepctations via `../reference`
24 it('identify as the page itself', function () {
25 // Example: /home/todd/github/karma-electron/test/integration-test/node-require-test.js
26 assert(/test[\/\\]integration-test[\/\\]node-require-test\.js$/.test(module.filename),
27 'Expected "' + module.filename + '" to end with "test/integration-test/node-require-test.js"');
28 assert.strictEqual(typeof module.exports, 'object');
29 // Example: /home/todd/github/karma-electron/test/integration-test/node-require-test.js
30 assert(/test[\/\\]integration-test[\/\\]node-require-test\.js$/.test(module.id),
31 'Expected "' + module.id + '" to end with "test/integration-test/node-require-test.js"');
32 assert.strictEqual(submodule.loaded, true);
33 // Example: /home/todd/github/karma-electron/node_modules/karma/static/context.html
34 assert(/karma[\/\\]static[\/\\]context\.html$/.test(module.parent.filename),
35 'Expected "' + module.parent.filename + '" to end with "karma/static/context.html"');
36 });
37 });
38
39 describe('in a child module', function () {
40 // DEV: Determined exepctations via `../reference`
41 it('identify as a standalone module', function () {
42 // Example: /home/todd/github/karma-electron/test/integration-test/test-files/submodule.js
43 assert(/test[\/\\]integration-test[\/\\]test-files[\/\\]submodule\.js$/.test(submodule.filename),
44 'Expected "' + submodule.filename + '" to end with "test/integration-test/test-files/submodule.js"');
45 // Verify `hello` property of `module.exports`
46 assert.strictEqual(submodule.exports.hello, 'world');
47 // Example: /home/todd/github/karma-electron/test/integration-test/test-files/submodule.js
48 assert(/test[\/\\]integration-test[\/\\]test-files[\/\\]submodule\.js$/.test(submodule.id),
49 'Expected "' + submodule.id + '" to end with "test/integration-test/test-files/submodule.js"');
50 assert.strictEqual(submodule.loaded, true);
51 assert.strictEqual(submodule.parent, module);
52
53 // Verify exported values
54 assert.strictEqual(submodule.hello, 'world');
55 // Example: /home/todd/github/karma-electron/test/integration-test/node-require-test.js
56 assert(/test[\/\\]integration-test[\/\\]test-files[\/\\]submodule\.js$/.test(submodule.filename),
57 'Expected "' + submodule.filename + '" to end with "test/integration-test/test-files/submodule.js"');
58 // Example: /home/todd/github/karma-electron/test/integration-test
59 assert(/test[\/\\]integration-test[\/\\]test-files$/.test(submodule.dirname),
60 'Expected "' + submodule.dirname + '" to end with "test/integration-test/test-files"');
61 });
62
63 it('has same window context as parent', function () {
64 assert.strictEqual(submodule.before, window.before);
65 });
66 });
67});