Skip to content

Commit

Permalink
added tests with fixture build-withConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroseus committed Mar 14, 2020
1 parent f5a395b commit 0499101
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ prog
.example('build --transpileOnly')
.option(
'--closureCompiler',
'EXPERIMENTAL: Use closure compiler to minify production bundle'
'EXPERIMENTAL: Use closure compiler to minify production bundle instead of terser'
)
.example('build --env production --closureCompiler')
.option(
Expand Down
7 changes: 0 additions & 7 deletions test/fixtures/build-withConfig/errors/ErrorDev.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/fixtures/build-withConfig/errors/ErrorProd.js

This file was deleted.

4 changes: 0 additions & 4 deletions test/fixtures/build-withConfig/errors/codes.json

This file was deleted.

2 changes: 1 addition & 1 deletion test/fixtures/build-withConfig/src/foo.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const foo = () => 'bar';
export const split = (str: string) => str.split('');
13 changes: 5 additions & 8 deletions test/fixtures/build-withConfig/src/index.ts
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 test/fixtures/build-withConfig/tsdx.config.closure-advanced.js
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',
},
};
7 changes: 7 additions & 0 deletions test/fixtures/build-withConfig/tsdx.config.closure-simple.js
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',
},
*/
};
22 changes: 0 additions & 22 deletions test/fixtures/build-withConfig/tsdx.config.js

This file was deleted.

79 changes: 79 additions & 0 deletions test/tests/tsdx-build-closure-compiler.test.js
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);
});
});

0 comments on commit 0499101

Please sign in to comment.