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

(test): use ts-node for tests for better testing DX #492

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
"pretty-quick": "^2.0.0",
"ps-tree": "^1.2.0",
"react": "^16.8.6",
"semver": "^7.1.1"
"semver": "^7.1.1",
"ts-node": "^8.6.2"
},
"husky": {
"hooks": {
Expand Down
12 changes: 7 additions & 5 deletions test/tests/tsdx-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const util = require('../fixtures/util');
shell.config.silent = false;

const stageName = 'stage-build';
const buildCommand =
'ts-node --project ../tsconfig.json --files ../src/index.ts build';

describe('tsdx build', () => {
beforeAll(() => {
Expand All @@ -17,7 +19,7 @@ describe('tsdx build', () => {
it('should compile files into a dist directory', () => {
util.setupStageWithFixture(stageName, 'build-default');

const output = shell.exec('node ../dist/index.js build --format esm,cjs');
const output = shell.exec(`${buildCommand} --format esm,cjs`);

expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
Expand All @@ -36,7 +38,7 @@ describe('tsdx build', () => {
it('should create the library correctly', () => {
util.setupStageWithFixture(stageName, 'build-default');

shell.exec('node ../dist/index.js build');
shell.exec(`${buildCommand}`);

const lib = require(`../../${stageName}/dist`);
expect(lib.foo()).toBe('bar');
Expand All @@ -48,7 +50,7 @@ describe('tsdx build', () => {
shell.mv('package.json', 'package-og.json');
shell.mv('package2.json', 'package.json');

const output = shell.exec('node ../dist/index.js build --format esm,cjs');
const output = shell.exec(`${buildCommand} --format esm,cjs`);
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();

// build-default files have been cleaned out
Expand Down Expand Up @@ -80,13 +82,13 @@ describe('tsdx build', () => {

it('should fail gracefully with exit code 1 when build failed', () => {
util.setupStageWithFixture(stageName, 'build-invalid');
const code = shell.exec('node ../dist/index.js build').code;
const code = shell.exec(`${buildCommand}`).code;
expect(code).toBe(1);
});

it('should only transpile and not type check', () => {
util.setupStageWithFixture(stageName, 'build-invalid');
const code = shell.exec('node ../dist/index.js build --transpileOnly').code;
const code = shell.exec(`${buildCommand} --transpileOnly`).code;

expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
Expand Down
28 changes: 27 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,11 @@ are-we-there-yet@~1.1.2:
delegates "^1.0.0"
readable-stream "^2.0.6"

arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==

argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
Expand Down Expand Up @@ -2324,6 +2329,11 @@ diff-sequences@^24.9.0:
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-24.9.0.tgz#5715d6244e2aa65f48bba0bc972db0b0b11e95b5"
integrity sha512-Dj6Wk3tWyTE+Fo1rW8v0Xhwk80um6yFYKbuAxc9c3EZxIHFDYwbi34Uk42u1CdnIiVorvt4RmlSDjIPyzGC2ew==

diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==

doctoc@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/doctoc/-/doctoc-1.4.0.tgz#3115aa61d0a92f0abb0672036918ea904f5b9e02"
Expand Down Expand Up @@ -4414,7 +4424,7 @@ make-dir@^3.0.0:
dependencies:
semver "^6.0.0"

make-error@1.x:
make-error@1.x, make-error@^1.1.1:
version "1.3.5"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8"
integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==
Expand Down Expand Up @@ -6420,6 +6430,17 @@ ts-jest@^24.0.2:
semver "^5.5"
yargs-parser "10.x"

ts-node@^8.6.2:
version "8.6.2"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.6.2.tgz#7419a01391a818fbafa6f826a33c1a13e9464e35"
integrity sha512-4mZEbofxGqLL2RImpe3zMJukvEvcO1XP8bj8ozBPySdCUXEcU5cIRwR0aM3R+VoZq7iXc8N86NC0FspGRqP4gg==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.6"
yn "3.1.1"

tslib@1.10.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
Expand Down Expand Up @@ -6876,3 +6897,8 @@ yargs@13.3.0, yargs@^13.3.0:
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^13.1.1"

yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==