Skip to content

Commit

Permalink
closure-compiler specific tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroseus committed Mar 14, 2020
1 parent 0499101 commit 60c6a28
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/build-withConfig/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export const sum = (a: number, b: number) => {

const bar = split('bar');

console.log(`${split('bar').join('')} ${sum(bar.length, -3)}`);
export const signature = `${split('bar').join('')} ${sum(bar.length, -3)}`;
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
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',
},
Expand Down
5 changes: 2 additions & 3 deletions test/fixtures/build-withConfig/tsdx.config.closure-simple.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
/* SIMPLE_OPTIMIZATIONS by default
closureCompilerOptions: {
compilation_level: 'SIMPLE_OPTIMIZATIONS',
//SIMPLE_OPTIMIZATIONS level is default option
//compilation_level: 'SIMPLE_OPTIMIZATIONS',
},
*/
};
21 changes: 10 additions & 11 deletions test/tests/tsdx-build-closure-compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('tsdx build with closure compiler', () => {
util.teardownStage(stageName);
});

it('should compile files with default options', () => {
it('should minify bundle with default options', () => {
util.setupStageWithFixture(stageName, 'build-withConfig');
shell.mv('-f', 'tsdx.config.closure-simple.js', 'tsdx.config.js');

Expand All @@ -36,12 +36,14 @@ describe('tsdx build with closure compiler', () => {

expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy();

output = shell.exec('node dist/index.js');
expect(output.code).toBe(0);
// only closure compiler minifies bundle to `signature="bar 0"`
output = shell.grep('bar 0', [
'dist/build-withconfig.esm.production.min.js',
]);
expect(/bar 0/.test(output.stdout)).toBeTruthy();
});

it('should compile files with advanced options', () => {
it('should minify bundle with advanced options', () => {
util.setupStageWithFixture(stageName, 'build-withConfig');
shell.mv('-f', 'tsdx.config.closure-advanced.js', 'tsdx.config.js');

Expand All @@ -50,11 +52,6 @@ describe('tsdx build with closure compiler', () => {
);
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')
Expand All @@ -68,8 +65,10 @@ describe('tsdx build with closure compiler', () => {

expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy();

output = shell.exec('node dist/index.js');
expect(output.code).toBe(0);
// only closure compiler minifies bundle to `signature="bar 0"`
output = shell.grep('bar 0', [
'dist/build-withconfig.esm.production.min.js',
]);
expect(/bar 0/.test(output.stdout)).toBeTruthy();
});

Expand Down

0 comments on commit 60c6a28

Please sign in to comment.