|
| 1 | +import rimrafCB from 'rimraf'; |
| 2 | +import {exec as execCB, ExecOptions} from 'child_process'; |
| 3 | +import * as path from 'path'; |
| 4 | +import {promisify} from 'util'; |
| 5 | + |
| 6 | +const rimraf = promisify(rimrafCB); |
| 7 | + |
| 8 | +const testDir = path.join(__dirname, 'build-parameters'); |
| 9 | + |
| 10 | +const exec = (cmd: string, options: ExecOptions): Promise<string> => |
| 11 | + new Promise((resolve, reject) => { |
| 12 | + execCB(cmd, options, (error, stdout, stderr) => { |
| 13 | + if (error) { |
| 14 | + reject(stderr || stdout || error.message); |
| 15 | + } else { |
| 16 | + resolve(stdout); |
| 17 | + } |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | +const buildProject = async (project: string) => { |
| 22 | + await exec(`cp tsconfig.${project}.json tsconfig.json`, {cwd: testDir}); |
| 23 | + |
| 24 | + await exec(`node ../../../lib/cli ./src/Example.ts ExampleType`, { |
| 25 | + cwd: testDir, |
| 26 | + }); |
| 27 | + |
| 28 | + await exec(`npx tsc --project ./tsconfig.json`, { |
| 29 | + cwd: testDir, |
| 30 | + }); |
| 31 | +}; |
| 32 | + |
| 33 | +beforeAll(() => exec('yarn build', {cwd: process.cwd()})); |
| 34 | + |
| 35 | +afterEach(() => |
| 36 | + Promise.all([ |
| 37 | + rimraf(path.join(testDir, 'lib')), |
| 38 | + exec('rm tsconfig.json', {cwd: testDir}), |
| 39 | + exec('rm src/Example.validator.ts', {cwd: testDir}), |
| 40 | + ]), |
| 41 | +); |
| 42 | + |
| 43 | +test('ESNext module settings', () => |
| 44 | + // We expect a project not to build correctly if it has ES module |
| 45 | + // target and no esModuleInterop. |
| 46 | + expect(buildProject('esnext')).rejects.toMatch('TS1202:')); |
| 47 | + |
| 48 | +test('ESNext interop module settings', () => buildProject('esnext-interop')); |
| 49 | + |
| 50 | +test('ES2015 module settings', () => |
| 51 | + expect(buildProject('es2015')).rejects.toMatch('TS1202:')); |
| 52 | + |
| 53 | +test('ES2015 interop module settings', () => buildProject('es2015-interop')); |
| 54 | + |
| 55 | +test('UMD module settings', () => buildProject('umd')); |
| 56 | + |
| 57 | +test('UMD interop module settings', () => buildProject('umd-interop')); |
| 58 | + |
| 59 | +test('System module settings', () => buildProject('system')); |
| 60 | + |
| 61 | +test('System interop module settings', () => buildProject('system-interop')); |
| 62 | + |
| 63 | +test('Common JS module settings', () => buildProject('commonjs')); |
| 64 | + |
| 65 | +test('Common JS interop module settings', () => |
| 66 | + buildProject('commonjs-interop')); |
0 commit comments