Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
build: combine the jest runners into a single global runner
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinpinto committed Dec 27, 2019
1 parent 0498785 commit 50bb45f
Show file tree
Hide file tree
Showing 16 changed files with 1,000 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- run: "yarn install --frozen-lockfile"
- run: "yarn lint"
- run: "yarn build"
- run: "yarn test"
- run: "yarn jest --colors --forceExit"

- uses: "./packages/automatic-releases/"
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tagged-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- run: "yarn install --frozen-lockfile"
- run: "yarn lint"
- run: "yarn build"
- run: "yarn test"
- run: "yarn jest --colors --forceExit"

- uses: "marvinpinto/action-automatic-releases@latest"
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- run: "yarn install --frozen-lockfile"
- run: "yarn lint"
- run: "yarn build"
- run: "yarn test"
- run: "yarn jest --colors --forceExit"

- uses: "./packages/keybase-notifications"
if: always()
Expand Down
14 changes: 14 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
'@babel/preset-typescript',
],
plugins: ['@babel/proposal-class-properties', '@babel/plugin-proposal-optional-chaining'],
};
35 changes: 29 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
module.exports = {
roots: ['<rootDir>/src', '<rootDir>/__tests__'],
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
moduleFileExtensions: ['js', 'ts', 'tsx'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.ts$': 'babel-jest',
'^.+\\.tsx$': 'babel-jest',
},
collectCoverage: true,
projects: ['<rootDir>/packages/*/jest.config.js'],
projects: [
{
name: 'keybase-notifications',
displayName: 'keybase-notifications',
testRegex: 'packages/keybase-notifications/__tests__',
testPathIgnorePatterns: ['/__tests__/payloads', '/__tests__/utils'],
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
},
{
name: 'automatic-releases',
displayName: 'automatic-releases',
testRegex: 'packages/automatic-releases/__tests__',
testPathIgnorePatterns: ['/__tests__/payloads', '/__tests__/utils/', '/__tests__/assets'],
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
},
],
coverageReporters: ['text'],
coverageThreshold: {
global: {
lines: 100,
},
},
setupFilesAfterEnv: ['<rootDir>/../../jest.setup.js'],
collectCoverageFrom: [
'**/packages/keybase-notifications/**/*.ts',
'**/packages/automatic-releases/**/*.ts',
'!**/__tests__/**',
'!**/dist/**',
'!**/packages/keybase-notifications/src/index.ts',
'!**/packages/keybase-notifications/src/utils.ts',
'!**/packages/automatic-releases/src/index.ts',
'!**/packages/automatic-releases/src/uploadReleaseArtifacts.ts',
],
};
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"prettierPaths": "*.{json,md,yaml,yml} .github/**/*.{json,md,yaml,yml} !package.json !lerna.json"
},
"scripts": {
"test": "lerna run test --stream --no-bail",
"test": "yarn jest --colors",
"build": "lerna run build --stream",
"clean": "lerna run clean --stream && rm -rf node_modules yarn-error.log",
"reinstall": "yarn clean; yarn install",
Expand All @@ -30,13 +30,19 @@
"release": "lerna version"
},
"devDependencies": {
"@babel/core": "^7.7.7",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-proposal-optional-chaining": "^7.7.5",
"@babel/preset-env": "^7.7.7",
"@babel/preset-typescript": "^7.7.7",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"@commitlint/config-lerna-scopes": "^8.2.0",
"@types/jest": "^24.0.24",
"@types/node": "^13.1.0",
"@typescript-eslint/eslint-plugin": "^2.13.0",
"@typescript-eslint/parser": "^2.13.0",
"babel-jest": "^24.9.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.8.0",
"eslint-plugin-jest": "^23.1.1",
Expand All @@ -45,7 +51,6 @@
"jest-circus": "^24.9.0",
"lerna": "^3.19.0",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"typescript": "^3.7.4"
},
"eslintIgnore": [
Expand Down
37 changes: 21 additions & 16 deletions packages/automatic-releases/__tests__/automaticReleases.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* eslint-disable @typescript-eslint/no-var-requires */

import * as process from 'process';
import * as path from 'path';
import nock from 'nock';
import fs from 'fs';
import {uploadReleaseArtifacts} from '../src/uploadReleaseArtifacts';
import {main} from '../src/main';

jest.mock('../src/uploadReleaseArtifacts');

describe('main handler processing automatic releases', () => {
const testGhToken = 'fake-secret-token';
Expand Down Expand Up @@ -33,6 +35,8 @@ describe('main handler processing automatic releases', () => {
process.env['GITHUB_ACTOR'] = 'marvinpinto';
process.env['GITHUB_EVENT_PATH'] = path.join(__dirname, 'payloads', 'git-push.json');
process.env['GITHUB_REPOSITORY'] = 'marvinpinto/private-actions-tester';

uploadReleaseArtifacts.mockImplementation().mockResolvedValue({});
});

afterEach(() => {
Expand All @@ -44,8 +48,7 @@ describe('main handler processing automatic releases', () => {

it('throws an error when "automatic_release_tag" is not supplied', async () => {
delete process.env.INPUT_AUTOMATIC_RELEASE_TAG;
const inst = require('../src/main');
await expect(inst.main()).rejects.toThrow(
await expect(main()).rejects.toThrow(
'The parameter "automatic_release_tag" was not set and this does not appear to be a GitHub tag event. (Event: refs/heads/automatic-pre-releaser)',
);
});
Expand All @@ -62,6 +65,11 @@ describe('main handler processing automatic releases', () => {
.get(`/repos/marvinpinto/private-actions-tester/compare/HEAD...${testGhSHA}`)
.reply(200, compareCommitsPayload);

const getRef = nock('https://api.github.com')
.matchHeader('authorization', `token ${testGhToken}`)
.get(`/repos/marvinpinto/private-actions-tester/git/refs/tags/${testInputAutomaticReleaseTag}`)
.reply(404);

const listAssociatedPRs = nock('https://api.github.com')
.matchHeader('authorization', `token ${testGhToken}`)
.get(`/repos/marvinpinto/private-actions-tester/commits/${testGhSHA}/pulls`)
Expand Down Expand Up @@ -101,21 +109,20 @@ describe('main handler processing automatic releases', () => {
// Output env variable should be empty
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBeUndefined();

const inst = require('../src/main');
inst.uploadReleaseArtifacts = jest.fn(() => Promise.resolve());
await inst.main();
await main();

expect(createRef.isDone()).toBe(true);
expect(getReleaseByTag.isDone()).toBe(true);
expect(deleteRelease.isDone()).toBe(false);
expect(createRelease.isDone()).toBe(true);
expect(getRef.isDone()).toBe(true);
expect(getCommitsSinceRelease.isDone()).toBe(true);
expect(listAssociatedPRs.isDone()).toBe(true);

expect(inst.uploadReleaseArtifacts).toHaveBeenCalledTimes(1);
expect(inst.uploadReleaseArtifacts.mock.calls[0][1]).toBe(releaseUploadUrl);
expect(uploadReleaseArtifacts).toHaveBeenCalledTimes(1);
expect(uploadReleaseArtifacts.mock.calls[0][1]).toBe(releaseUploadUrl);
// Should not attempt to upload any release artifacts, as there are none
expect(inst.uploadReleaseArtifacts.mock.calls[0][2]).toEqual([]);
expect(uploadReleaseArtifacts.mock.calls[0][2]).toEqual([]);

// Should populate the output env variable
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBe(testInputAutomaticReleaseTag);
Expand Down Expand Up @@ -193,9 +200,7 @@ describe('main handler processing automatic releases', () => {
// Output env variable should be empty
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBeUndefined();

const inst = require('../src/main');
inst.uploadReleaseArtifacts = jest.fn(() => Promise.resolve());
await inst.main();
await main();

expect(createRef.isDone()).toBe(true);
expect(updateRef.isDone()).toBe(true);
Expand All @@ -206,9 +211,9 @@ describe('main handler processing automatic releases', () => {
expect(getCommitsSinceRelease.isDone()).toBe(true);
expect(listAssociatedPRs.isDone()).toBe(true);

expect(inst.uploadReleaseArtifacts).toHaveBeenCalledTimes(1);
expect(inst.uploadReleaseArtifacts.mock.calls[0][1]).toBe(releaseUploadUrl);
expect(inst.uploadReleaseArtifacts.mock.calls[0][2]).toEqual(['file1.txt', 'file2.txt', '*.jar']);
expect(uploadReleaseArtifacts).toHaveBeenCalledTimes(1);
expect(uploadReleaseArtifacts.mock.calls[0][1]).toBe(releaseUploadUrl);
expect(uploadReleaseArtifacts.mock.calls[0][2]).toEqual(['file1.txt', 'file2.txt', '*.jar']);

// Should populate the output env variable
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBe(testInputAutomaticReleaseTag);
Expand Down
26 changes: 17 additions & 9 deletions packages/automatic-releases/__tests__/taggedReleases.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/camelcase */

import * as process from 'process';
import * as path from 'path';
import nock from 'nock';
import fs from 'fs';
import {uploadReleaseArtifacts} from '../src/uploadReleaseArtifacts';
import {main} from '../src/main';

jest.mock('../src/uploadReleaseArtifacts');

describe('main handler processing tagged releases', () => {
const testGhToken = 'fake-secret-token';
Expand All @@ -29,6 +33,8 @@ describe('main handler processing tagged releases', () => {
process.env['GITHUB_ACTOR'] = 'marvinpinto';
process.env['GITHUB_EVENT_PATH'] = path.join(__dirname, 'payloads', 'git-push.json');
process.env['GITHUB_REPOSITORY'] = 'marvinpinto/private-actions-tester';

uploadReleaseArtifacts.mockImplementation().mockResolvedValue({});
});

afterEach(() => {
Expand All @@ -40,8 +46,7 @@ describe('main handler processing tagged releases', () => {

it('throws an error if the github event tag does not conform to semantic versioning', async () => {
process.env['GITHUB_REF'] = 'refs/tags/faketag';
const inst = require('../src/main');
await expect(inst.main()).rejects.toThrow(
await expect(main()).rejects.toThrow(
'The parameter "automatic_release_tag" was not set and the current tag "faketag" does not appear to conform to semantic versioning.',
);
});
Expand Down Expand Up @@ -90,6 +95,11 @@ describe('main handler processing tagged releases', () => {
.get(`/repos/marvinpinto/private-actions-tester/compare/HEAD...${testGhSHA}`)
.reply(200, compareCommitsPayload);

const getRef = nock('https://api.github.com')
.matchHeader('authorization', `token ${testGhToken}`)
.get(`/repos/marvinpinto/private-actions-tester/git/refs/tags/v0.0.0`)
.reply(404);

const listAssociatedPRs = nock('https://api.github.com')
.matchHeader('authorization', `token ${testGhToken}`)
.get(`/repos/marvinpinto/private-actions-tester/commits/${testGhSHA}/pulls`)
Expand All @@ -111,18 +121,16 @@ describe('main handler processing tagged releases', () => {
// Output env variable should be empty
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBeUndefined();

const inst = require('../src/main');
inst.uploadReleaseArtifacts = jest.fn(() => Promise.resolve());
await inst.main();
await main();

expect(getCommitsSinceRelease.isDone()).toBe(true);
expect(listAssociatedPRs.isDone()).toBe(true);
expect(createRelease.isDone()).toBe(true);
expect(searchForPreviousReleaseTag.isDone()).toBe(true);

expect(inst.uploadReleaseArtifacts).toHaveBeenCalledTimes(1);
expect(inst.uploadReleaseArtifacts.mock.calls[0][1]).toBe(releaseUploadUrl);
expect(inst.uploadReleaseArtifacts.mock.calls[0][2]).toEqual(['file1.txt', 'file2.txt', '*.jar']);
expect(uploadReleaseArtifacts).toHaveBeenCalledTimes(1);
expect(uploadReleaseArtifacts.mock.calls[0][1]).toBe(releaseUploadUrl);
expect(uploadReleaseArtifacts.mock.calls[0][2]).toEqual(['file1.txt', 'file2.txt', '*.jar']);

// Should populate the output env variable
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBe('v0.0.1');
Expand Down
9 changes: 0 additions & 9 deletions packages/automatic-releases/jest.config.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/automatic-releases/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"scripts": {
"build": "webpack --config webpack.config.js --colors",
"test": "jest --color --forceExit",
"clean": "rm -rf node_modules yarn-error.log dist",
"lint": "yarn run lint:eslint && yarn run lint:prettier",
"lint:eslint": "eslint --color --max-warnings=0 $npm_package_config_eslintPaths",
Expand Down

0 comments on commit 50bb45f

Please sign in to comment.