-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests with fixture build-withConfig
- Loading branch information
Showing
10 changed files
with
105 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const foo = () => 'bar'; | ||
export const split = (str: string) => str.split(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import invariant from 'tiny-invariant'; | ||
import warning from 'tiny-warning'; | ||
invariant(true, 'error occurred! o no'); | ||
warning(false, 'warning - water is wet'); | ||
export { foo } from './foo'; | ||
import { split } from './foo'; | ||
|
||
export const sum = (a: number, b: number) => { | ||
if ('development' === process.env.NODE_ENV) { | ||
console.log('fuck'); | ||
} | ||
return a + b; | ||
}; | ||
|
||
const bar = split('bar'); | ||
|
||
console.log(`${split('bar').join('')} ${sum(bar.length, -3)}`); |
12 changes: 12 additions & 0 deletions
12
test/fixtures/build-withConfig/tsdx.config.closure-advanced.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const fs = require('fs-extra'); | ||
|
||
module.exports = { | ||
rollup(config, options) { | ||
const plugins = config.plugins.map(plugin => plugin.name); | ||
fs.writeJSON('./plugins.json', plugins); | ||
return config; | ||
}, | ||
closureCompilerOptions: { | ||
compilation_level: 'ADVANCED_OPTIMIZATIONS', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
/* SIMPLE_OPTIMIZATIONS by default | ||
closureCompilerOptions: { | ||
compilation_level: 'SIMPLE_OPTIMIZATIONS', | ||
}, | ||
*/ | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
|
||
const shell = require('shelljs'); | ||
const util = require('../fixtures/util'); | ||
|
||
shell.config.silent = false; | ||
|
||
const stageName = 'stage-build-closure-compiler'; | ||
|
||
describe('tsdx build with closure compiler', () => { | ||
beforeAll(() => { | ||
util.teardownStage(stageName); | ||
}); | ||
|
||
it('should compile files with default options', () => { | ||
util.setupStageWithFixture(stageName, 'build-withConfig'); | ||
shell.mv('-f', 'tsdx.config.closure-simple.js', 'tsdx.config.js'); | ||
|
||
let output = shell.exec( | ||
'node ../dist/index.js build --env production --closureCompiler' | ||
); | ||
expect(output.code).toBe(0); | ||
|
||
expect(shell.test('-f', 'dist/index.js')).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withconfig.cjs.development.js') | ||
).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withconfig.cjs.production.min.js') | ||
).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withconfig.esm.production.min.js') | ||
).toBeTruthy(); | ||
|
||
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy(); | ||
|
||
output = shell.exec('node dist/index.js'); | ||
expect(output.code).toBe(0); | ||
expect(/bar 0/.test(output.stdout)).toBeTruthy(); | ||
}); | ||
|
||
it('should compile files with advanced options', () => { | ||
util.setupStageWithFixture(stageName, 'build-withConfig'); | ||
shell.mv('-f', 'tsdx.config.closure-advanced.js', 'tsdx.config.js'); | ||
|
||
let output = shell.exec( | ||
'node ../dist/index.js build --env production --closureCompiler' | ||
); | ||
expect(output.code).toBe(0); | ||
|
||
// ensure we use closure-compiler instead of terser | ||
const plugins = require(`../../${stageName}/plugins.json`); | ||
expect(plugins.includes('closure-compiler')).toBeTruthy(); | ||
expect(plugins.includes('terser')).toBeFalsy(); | ||
|
||
expect(shell.test('-f', 'dist/index.js')).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withconfig.cjs.development.js') | ||
).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withconfig.cjs.production.min.js') | ||
).toBeTruthy(); | ||
expect( | ||
shell.test('-f', 'dist/build-withconfig.esm.production.min.js') | ||
).toBeTruthy(); | ||
|
||
expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy(); | ||
|
||
output = shell.exec('node dist/index.js'); | ||
expect(output.code).toBe(0); | ||
expect(/bar 0/.test(output.stdout)).toBeTruthy(); | ||
}); | ||
|
||
afterEach(() => { | ||
util.teardownStage(stageName); | ||
}); | ||
}); |