Skip to content

Commit

Permalink
Smoke tests (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavohenke committed Feb 25, 2024
1 parent feac92b commit fd21485
Show file tree
Hide file tree
Showing 16 changed files with 346 additions and 8 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -55,9 +55,13 @@ jobs:
- name: Install dependencies
run: pnpm install && pnpm add --global concurrently

- name: Build & Test
- name: Build & Unit Test
run: concurrently --prefix none --group "pnpm:build" "pnpm:test"

- name: Smoke Test
# Don't collect coverage here as it overrides the unit test's coverage
run: pnpm test:smoke --coverage=false

- name: Submit coverage
uses: coverallsapp/github-action@master
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
# Outputs
/dist
dist

# Logs
*.log
Expand Down
29 changes: 24 additions & 5 deletions jest.config.js
@@ -1,11 +1,30 @@
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
// Need to extend from a base config because projects don't inherit configurations as documented
// https://github.com/jestjs/jest/issues/11411
/** @type {import('@jest/types').Config.InitialProjectOptions} */
const baseConfig = {
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
'.*': ['@swc/jest'],
},
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts', '!src/index.ts'],
testPathIgnorePatterns: ['/node_modules/', '/dist'],
};

/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
collectCoverage: true,
projects: [
{
...baseConfig,
displayName: 'unit',
collectCoverageFrom: ['src/**/*.ts', '!src/index.ts'],
// (src|bin) doesn't seem to work on Windows
testMatch: ['src', 'bin'].map((dir) => `<rootDir>/${dir}/**/*.spec.ts`),
},
{
...baseConfig,
displayName: 'smoke',
testMatch: ['<rootDir>/tests/**/*.spec.ts'],
},
],
};

module.exports = config;
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -35,7 +35,8 @@
"lint:fix": "pnpm run lint --fix",
"prepublishOnly": "safe-publish-latest && pnpm run build",
"report-coverage": "cat coverage/lcov.info | coveralls",
"test": "jest",
"test": "jest --selectProjects unit",
"test:smoke": "jest --selectProjects smoke",
"prepare": "husky install"
},
"repository": {
Expand Down
3 changes: 3 additions & 0 deletions tests/cjs-import/package.json
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
15 changes: 15 additions & 0 deletions tests/cjs-import/smoke-test.ts
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { ConcurrentlyResult } from 'concurrently';
import concurrently, { concurrently as concurrently2, createConcurrently } from 'concurrently';

const result: ConcurrentlyResult = concurrently(['ls'], {
raw: true,
});

const result2: ConcurrentlyResult = concurrently2(['ls'], {
killOthers: ['failure'],
});

const result3: ConcurrentlyResult = createConcurrently(['ls'], {
successCondition: 'all',
});
8 changes: 8 additions & 0 deletions tests/cjs-import/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "dist",
"module": "CommonJS",
"moduleResolution": "Node",
"skipLibCheck": true
}
}
3 changes: 3 additions & 0 deletions tests/cjs-require/package.json
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
17 changes: 17 additions & 0 deletions tests/cjs-require/smoke-test.ts
@@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import concurrently = require('concurrently');

const { concurrently: concurrently2, createConcurrently } = concurrently;

const result: concurrently.ConcurrentlyResult = concurrently(['ls'], {
raw: true,
});

const result2: concurrently.ConcurrentlyResult = concurrently2(['ls'], {
killOthers: ['failure'],
});

const result3: concurrently.ConcurrentlyResult = createConcurrently(['ls'], {
successCondition: 'all',
});
8 changes: 8 additions & 0 deletions tests/cjs-require/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "dist",
"module": "CommonJS",
"moduleResolution": "Node",
"skipLibCheck": true
}
}
3 changes: 3 additions & 0 deletions tests/esm/package.json
@@ -0,0 +1,3 @@
{
"type": "module"
}
15 changes: 15 additions & 0 deletions tests/esm/smoke-test.ts
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { ConcurrentlyResult } from 'concurrently';
import concurrently, { concurrently as concurrently2, createConcurrently } from 'concurrently';

const result: ConcurrentlyResult = concurrently(['ls'], {
raw: true,
});

const result2: ConcurrentlyResult = concurrently2(['ls'], {
killOthers: ['failure'],
});

const result3: ConcurrentlyResult = createConcurrently(['ls'], {
successCondition: 'all',
});
7 changes: 7 additions & 0 deletions tests/esm/tsconfig.json
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"outDir": "dist",
"module": "Node16",
"moduleResolution": "Node16"
}
}
8 changes: 8 additions & 0 deletions tests/package.json
@@ -0,0 +1,8 @@
{
"dependencies": {
"concurrently": "file:.."
},
"scripts": {
"test": "pnpm --prefix .. test -- --selectProjects smoke"
}
}
206 changes: 206 additions & 0 deletions tests/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions tests/smoke-tests.spec.ts
@@ -0,0 +1,21 @@
import { exec as originalExec } from 'child_process';
import * as util from 'util';

const exec = util.promisify(originalExec);

beforeAll(async () => {
await exec('pnpm build', { cwd: `${__dirname}/..` });
await exec('pnpm install', { cwd: __dirname });
}, 10000);

it.each(['cjs-import', 'cjs-require', 'esm'])(

Check warning on line 11 in tests/smoke-tests.spec.ts

View workflow job for this annotation

GitHub Actions / Check

Test has no assertions
'%s',
async (project) => {
// Use as separate execs as tsc outputs to stdout, instead of stderr, and so its text isn't shown
await exec(`tsc -p ${project}`, { cwd: __dirname }).catch((err) =>
Promise.reject(err.stdout),
);
await exec(`node ${project}/dist/smoke-test.js`, { cwd: __dirname });
},
10000,
);

0 comments on commit fd21485

Please sign in to comment.