|
| 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