Skip to content

Commit 9c265a8

Browse files
committedJul 14, 2020
test: add smoke tests for importing as esm module and requiring as commonjs module
1 parent fca039d commit 9c265a8

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import assert from 'assert';
2+
3+
// eslint-disable-next-line import/no-unresolved
4+
import webExt from 'web-ext';
5+
6+
assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort());
7+
assert.equal(typeof webExt.cmd.run, 'function');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const assert = require('assert');
2+
3+
const webExt = require('web-ext');
4+
5+
assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort());
6+
assert.equal(typeof webExt.cmd.run, 'function');

‎tests/functional/common.js

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export const webExt = process.env.TEST_WEB_EXT_BIN ?
1818
path.join(projectDir, 'bin', 'web-ext');
1919
export const fixturesDir = path.join(functionalTestsDir, '..', 'fixtures');
2020
export const minimalAddonPath = path.join(fixturesDir, 'minimal-web-ext');
21+
export const fixtureEsmImport = path.join(fixturesDir, 'import-as-esm');
22+
export const fixtureCjsRequire = path.join(fixturesDir, 'require-as-cjs');
2123
export const fakeFirefoxPath = path.join(
2224
functionalTestsDir,
2325
process.platform === 'win32' ?

‎tests/functional/test.lib.imports.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* @flow */
2+
import {execSync} from 'child_process';
3+
import path from 'path';
4+
5+
import {describe, it, before, after} from 'mocha';
6+
import shell from 'shelljs';
7+
8+
import {
9+
withTempDir, fixtureEsmImport, fixtureCjsRequire,
10+
} from './common';
11+
12+
const npm = shell.which('npm');
13+
const node = shell.which('node');
14+
15+
describe('web-ext imported as a library', () => {
16+
before(function() {
17+
// Only run this test in automation, to avoid running
18+
// the npm link/npm unlink commands used to prepare
19+
// the test environment for these tests.
20+
if (!process.env.CI) {
21+
this.skip();
22+
}
23+
24+
execSync(`${npm} link`, {
25+
cwd: path.resolve(path.join(__dirname, '..', '..')),
26+
});
27+
});
28+
29+
after(() => {
30+
execSync(`${npm} unlink`, {
31+
cwd: path.resolve(path.join(__dirname, '..', '..')),
32+
});
33+
});
34+
35+
it('can be imported as an ESM module', async () => {
36+
await withTempDir(async (tmpDir) => {
37+
execSync(`${npm} link web-ext`, {cwd: tmpDir.path()});
38+
shell.cp('-rf', `${fixtureEsmImport}/*`, tmpDir.path());
39+
execSync(`${node} --experimental-modules test-import.mjs`, {
40+
cwd: tmpDir.path(),
41+
});
42+
});
43+
});
44+
45+
it('can be imported as a CommonJS module', async () => {
46+
await withTempDir(async (tmpDir) => {
47+
execSync(`${npm} link web-ext`, {cwd: tmpDir.path()});
48+
shell.cp('-rf', `${fixtureCjsRequire}/*`, tmpDir.path());
49+
execSync(`${node} --experimental-modules test-require.js`, {
50+
cwd: tmpDir.path(),
51+
});
52+
});
53+
});
54+
});

0 commit comments

Comments
 (0)
Please sign in to comment.