From a5eb3d8bea122219f1be6710050ae31be5b0dbdd Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Fri, 10 Jan 2020 10:30:16 +0100 Subject: [PATCH] Fix jest test in CI Jest runs out of memory when run in Docker, possibly because of a memory leak in ts-jest. The tests will now run after the build, on the built *.js files. As a consequence, the jest tests will run faster because ts-jest will no longer be invoked in ci. Check the package.json test:ci script for more info. https://github.com/facebook/jest/issues/7874 https://github.com/facebook/jest/issues/9081 --- .drone.yml | 6 +++--- package.json | 7 +++++-- packages/captcha/src/audio.test.ts | 4 ++-- packages/captcha/src/run.test.ts | 4 ++-- packages/config/src/ConfigReader.test.ts | 6 +++--- packages/config/{src => }/test-files/.gitignore | 0 packages/config/{src => }/test-files/config/default.yml | 0 packages/config/{src => }/test-files/config/test.yml | 0 packages/jsonrpc/jest.config.js | 1 + packages/jsonrpc/src/redux.test.ts | 4 ---- packages/jsonrpc/src/remote.test.ts | 4 ---- packages/server/jest.config.js | 1 + packages/server/src/test-utils/TestUtils.ts | 2 -- 13 files changed, 17 insertions(+), 22 deletions(-) rename packages/config/{src => }/test-files/.gitignore (100%) rename packages/config/{src => }/test-files/config/default.yml (100%) rename packages/config/{src => }/test-files/config/test.yml (100%) diff --git a/.drone.yml b/.drone.yml index 8aacc6e..8f0a746 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,10 +10,10 @@ steps: - npm install - npm run lint - npm run bootstrap - - ./node_modules/.bin/jest - - ./node_modules/.bin/lerna exec rondo -- build --esm + - npm run jest + - npm run esm --- kind: signature -hmac: 75cb50df9833086e4b9705f592b78ee8c12479ab8b2041577c4660ecc8364295 +hmac: ccaae75bbb4cb95e9e82761ffaf6fe1293e5a35b4b7dca077f38837e44e567fa ... diff --git a/package.json b/package.json index 2cb72a5..018a844 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,11 @@ { "scripts": { - "clean": "lerna exec rimraf -- lib/ esm/ *.tsbuildinfo", + "clean": "lerna exec rimraf --stream -- lib/ esm/ *.tsbuildinfo", "lint": "eslint --ext .ts,.tsx,.ts .", - "bootstrap": "ttsc --build packages/scripts && lerna exec rondo -- build" + "bootstrap": "ttsc --build packages/scripts && lerna exec rondo --stream -- build", + "esm": "lerna exec rondo --stream -- build --esm", + "test:ci": "jest --roots '/lib' --testRegex '\\.test\\.js$'", + "test": "jest" }, "dependencies": { "@rondo.dev/argparse": "file:packages/argparse", diff --git a/packages/captcha/src/audio.test.ts b/packages/captcha/src/audio.test.ts index 2609d10..8ad787f 100644 --- a/packages/captcha/src/audio.test.ts +++ b/packages/captcha/src/audio.test.ts @@ -3,7 +3,7 @@ import session from 'express-session' import cookieParser from 'cookie-parser' import request from 'supertest' import { audio, speak } from './audio' -import { join } from 'path' +import { extname, join } from 'path' describe('speak', () => { it('writes speech data to stdin and returns rw streams', async () => { @@ -23,7 +23,7 @@ describe('speak', () => { const command = { cmd: process.argv[0], - args: [join(__dirname, 'testProcess.ts')], + args: [join(__dirname, 'testProcess' + extname(__filename))], contentType: 'text/plain', } const rw = await speak('mytest', [command]) diff --git a/packages/captcha/src/run.test.ts b/packages/captcha/src/run.test.ts index a829b3a..6dbc748 100644 --- a/packages/captcha/src/run.test.ts +++ b/packages/captcha/src/run.test.ts @@ -1,6 +1,6 @@ import { run } from './run' import { getError } from '@rondo.dev/test-utils' -import { join } from 'path' +import { extname, join } from 'path' describe('run', () => { @@ -22,7 +22,7 @@ describe('run', () => { it('runs a process and returns stdin/stdout/contentType', async () => { const result = await run({ cmd: process.argv[0], - args: [join(__dirname, 'testProcess.ts')], + args: [join(__dirname, 'testProcess' + extname(__filename))], contentType: 'text/plain', }) expect(result.contentType).toBe('text/plain') diff --git a/packages/config/src/ConfigReader.test.ts b/packages/config/src/ConfigReader.test.ts index 6dbcf1b..09419aa 100644 --- a/packages/config/src/ConfigReader.test.ts +++ b/packages/config/src/ConfigReader.test.ts @@ -6,7 +6,7 @@ describe('ConfigReader', () => { beforeAll(() => { writeFileSync( - join(__dirname, 'test-files', 'package.json'), + join(__dirname, '..', 'test-files', 'package.json'), '{}', ) }) @@ -20,7 +20,7 @@ describe('ConfigReader', () => { it('reads and merges configuration files from CWD', () => { const config = new ConfigReader( - join(__dirname, 'test-files', 'dir'), + join(__dirname, '..', 'test-files', 'dir'), '/tmp/path', ).read() expect(config.value()).toEqual({ @@ -53,7 +53,7 @@ describe('ConfigReader', () => { it('succeeds when config from env variable is read', () => { process.env.CONFIG = '---\na: 2' const config = new ConfigReader( - join(__dirname, 'test-files', 'dir'), + join(__dirname, '..', 'test-files', 'dir'), '/tmp/path', ).read() expect(config.value()).toEqual({ diff --git a/packages/config/src/test-files/.gitignore b/packages/config/test-files/.gitignore similarity index 100% rename from packages/config/src/test-files/.gitignore rename to packages/config/test-files/.gitignore diff --git a/packages/config/src/test-files/config/default.yml b/packages/config/test-files/config/default.yml similarity index 100% rename from packages/config/src/test-files/config/default.yml rename to packages/config/test-files/config/default.yml diff --git a/packages/config/src/test-files/config/test.yml b/packages/config/test-files/config/test.yml similarity index 100% rename from packages/config/src/test-files/config/test.yml rename to packages/config/test-files/config/test.yml diff --git a/packages/jsonrpc/jest.config.js b/packages/jsonrpc/jest.config.js index 777a5de..c9d5160 100644 --- a/packages/jsonrpc/jest.config.js +++ b/packages/jsonrpc/jest.config.js @@ -4,6 +4,7 @@ module.exports = { compiler: 'ttypescript', }, }, + testEnvironment: 'node', roots: [ '/src', ], diff --git a/packages/jsonrpc/src/redux.test.ts b/packages/jsonrpc/src/redux.test.ts index 1c4537e..d904b32 100644 --- a/packages/jsonrpc/src/redux.test.ts +++ b/packages/jsonrpc/src/redux.test.ts @@ -1,7 +1,3 @@ -/** - * @jest-environment node - */ - import { createStore } from '@rondo.dev/redux' import bodyParser from 'body-parser' import express from 'express' diff --git a/packages/jsonrpc/src/remote.test.ts b/packages/jsonrpc/src/remote.test.ts index 611422b..c414798 100644 --- a/packages/jsonrpc/src/remote.test.ts +++ b/packages/jsonrpc/src/remote.test.ts @@ -1,7 +1,3 @@ -/** - * @jest-environment node - */ - import bodyParser from 'body-parser' import express from 'express' import {AddressInfo} from 'net' diff --git a/packages/server/jest.config.js b/packages/server/jest.config.js index ec06ec7..11f6c43 100644 --- a/packages/server/jest.config.js +++ b/packages/server/jest.config.js @@ -2,6 +2,7 @@ module.exports = { roots: [ '/src', ], + testEnvironment: 'node', transform: { '^.+\\.tsx?$': 'ts-jest', }, diff --git a/packages/server/src/test-utils/TestUtils.ts b/packages/server/src/test-utils/TestUtils.ts index 52e43aa..089bae4 100644 --- a/packages/server/src/test-utils/TestUtils.ts +++ b/packages/server/src/test-utils/TestUtils.ts @@ -138,8 +138,6 @@ export class TestUtils { }) .expect(200) - console.log('registered?') - const cookies = this.getCookies(response.header['set-cookie']) return {