Skip to content

Commit f46c04c

Browse files
committed
closure-compiler specific tests
1 parent 415e78d commit f46c04c

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

test/fixtures/build-withConfig/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export const sum = (a: number, b: number) => {
66

77
const bar = split('bar');
88

9-
console.log(`${split('bar').join('')} ${sum(bar.length, -3)}`);
9+
export const signature = `${split('bar').join('')} ${sum(bar.length, -3)}`;

test/fixtures/build-withConfig/tsdx.config.closure-advanced.js

-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
const fs = require('fs-extra');
2-
31
module.exports = {
4-
rollup(config, options) {
5-
const plugins = config.plugins.map(plugin => plugin.name);
6-
fs.writeJSON('./plugins.json', plugins);
7-
return config;
8-
},
92
closureCompilerOptions: {
103
compilation_level: 'ADVANCED_OPTIMIZATIONS',
114
},
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = {
2-
/* SIMPLE_OPTIMIZATIONS by default
32
closureCompilerOptions: {
4-
compilation_level: 'SIMPLE_OPTIMIZATIONS',
3+
//SIMPLE_OPTIMIZATIONS level is default option
4+
//compilation_level: 'SIMPLE_OPTIMIZATIONS',
55
},
6-
*/
76
};

test/tests/tsdx-build-closure-compiler.test.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('tsdx build with closure compiler', () => {
1414
util.teardownStage(stageName);
1515
});
1616

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

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

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

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

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

@@ -50,11 +52,6 @@ describe('tsdx build with closure compiler', () => {
5052
);
5153
expect(output.code).toBe(0);
5254

53-
// ensure we use closure-compiler instead of terser
54-
const plugins = require(`../../${stageName}/plugins.json`);
55-
expect(plugins.includes('closure-compiler')).toBeTruthy();
56-
expect(plugins.includes('terser')).toBeFalsy();
57-
5855
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
5956
expect(
6057
shell.test('-f', 'dist/build-withconfig.cjs.development.js')
@@ -68,8 +65,10 @@ describe('tsdx build with closure compiler', () => {
6865

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

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

0 commit comments

Comments
 (0)