Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor): split build tests into separate files per fixture #621

Merged
merged 2 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 75 additions & 0 deletions test/tests/tsdx-build-default.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const shell = require('shelljs');
const util = require('../fixtures/util');

shell.config.silent = false;

const fixtureName = 'build-default';
const stageName = `stage-${fixtureName}`;

describe('tsdx build :: zero-config defaults', () => {
beforeAll(() => {
util.teardownStage(stageName);
util.setupStageWithFixture(stageName, fixtureName);
});

it('should compile files into a dist directory', () => {
const output = shell.exec('node ../dist/index.js build');

expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
shell.test('-f', 'dist/build-default.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-default.cjs.production.min.js')
).toBeTruthy();
expect(shell.test('-f', 'dist/build-default.esm.js')).toBeTruthy();

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

expect(output.code).toBe(0);
});

it('should create the library correctly', () => {
agilgur5 marked this conversation as resolved.
Show resolved Hide resolved
const lib = require(`../../${stageName}/dist`);
expect(lib.foo()).toBe('bar');
expect(lib.__esModule).toBe(true);
});

it('should clean the dist directory before rebuilding', () => {
shell.mv('package.json', 'package-og.json');
shell.mv('package2.json', 'package.json');

const output = shell.exec('node ../dist/index.js build');
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();

// build-default files have been cleaned out
expect(
shell.test('-f', 'dist/build-default.cjs.development.js')
).toBeFalsy();
expect(
shell.test('-f', 'dist/build-default.cjs.production.min.js')
).toBeFalsy();
expect(shell.test('-f', 'dist/build-default.esm.js')).toBeFalsy();

// build-default-2 files have been added
expect(
shell.test('-f', 'dist/build-default-2.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-default-2.cjs.production.min.js')
).toBeTruthy();
expect(shell.test('-f', 'dist/build-default-2.esm.js')).toBeTruthy();

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

expect(output.code).toBe(0);

// reset package.json files
shell.mv('package.json', 'package2.json');
shell.mv('package-og.json', 'package.json');
});

afterAll(() => {
util.teardownStage(stageName);
});
});
40 changes: 40 additions & 0 deletions test/tests/tsdx-build-invalid.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const shell = require('shelljs');
const util = require('../fixtures/util');

shell.config.silent = false;

const fixtureName = 'build-invalid';
const stageName = `stage-${fixtureName}`;

describe('tsdx build :: invalid build', () => {
beforeAll(() => {
util.teardownStage(stageName);
util.setupStageWithFixture(stageName, fixtureName);
});

it('should fail gracefully with exit code 1 when build failed', () => {
const code = shell.exec('node ../dist/index.js build').code;
expect(code).toBe(1);
});

it('should only transpile and not type check', () => {
const code = shell.exec('node ../dist/index.js build --transpileOnly').code;

expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
shell.test('-f', 'dist/build-invalid.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-invalid.cjs.production.min.js')
).toBeTruthy();
expect(shell.test('-f', 'dist/build-invalid.esm.js')).toBeTruthy();

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

expect(code).toBe(0);
});

afterAll(() => {
util.teardownStage(stageName);
});
});
63 changes: 63 additions & 0 deletions test/tests/tsdx-build-withTsconfig.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const shell = require('shelljs');
const util = require('../fixtures/util');

shell.config.silent = false;

const fixtureName = 'build-withTsconfig';
const stageName = `stage-${fixtureName}`;

describe('tsdx build :: build with custom tsconfig.json options', () => {
beforeAll(() => {
util.teardownStage(stageName);
util.setupStageWithFixture(stageName, fixtureName);
});

it('should use the declarationDir when set', () => {
const output = shell.exec('node ../dist/index.js build');

expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
shell.test('-f', 'dist/build-withtsconfig.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-withtsconfig.cjs.production.min.js')
).toBeTruthy();
expect(shell.test('-f', 'dist/build-withtsconfig.esm.js')).toBeTruthy();

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

expect(output.code).toBe(0);
});

it('should set __esModule according to esModuleInterop', () => {
const lib = require(`../../${stageName}/dist/build-withtsconfig.cjs.production.min.js`);
// if esModuleInterop: false, no __esModule is added, therefore undefined
expect(lib.__esModule).toBe(undefined);
});

it('should read custom --tsconfig path', () => {
const output = shell.exec(
'node ../dist/index.js build --format cjs --tsconfig ./src/tsconfig.json'
);

expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
shell.test('-f', 'dist/build-withtsconfig.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-withtsconfig.cjs.production.min.js')
).toBeTruthy();

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

expect(output.code).toBe(0);
});

afterAll(() => {
util.teardownStage(stageName);
});
});
164 changes: 0 additions & 164 deletions test/tests/tsdx-build.test.js

This file was deleted.