Skip to content

Commit bf2a24f

Browse files
authored
Add tests for release script (#11454)
* Install jest * Configure jest script * Fix eslintrc * Add @types/jest * Add test for validate-new-version * Fix eslintrc * Add workflow file * Add node version * cd to script/release * Fix workflow file * Fix version * Ignore from root * Update yarn.lock * Set defaults.run.working-directory
1 parent 2bbe331 commit bf2a24f

File tree

8 files changed

+2520
-89
lines changed

8 files changed

+2520
-89
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ module.exports = {
153153
"tests/format/**/jsfmt.spec.js",
154154
"tests/config/**/*.js",
155155
"tests/integration/**/*.js",
156+
"scripts/release/__tests__/**/*.spec.js",
156157
],
157158
env: {
158159
jest: true,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release_Script_Test
2+
3+
defaults:
4+
run:
5+
working-directory: scripts/release
6+
7+
on:
8+
push:
9+
paths:
10+
- "scripts/release/**"
11+
- ".github/workflows/release-script-test.yml"
12+
pull_request:
13+
paths:
14+
- "scripts/release/**"
15+
- ".github/workflows/release-script-test.yml"
16+
17+
jobs:
18+
test:
19+
name: Test
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/[email protected]
24+
25+
- name: Setup Node.js
26+
uses: actions/[email protected]
27+
with:
28+
version: "14"
29+
cache: "yarn"
30+
31+
- name: Install Dependencies
32+
run: yarn install --frozen-lockfile
33+
34+
- name: Test
35+
run: yarn test

jest.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ module.exports = {
7171
"prettier-local": "<rootDir>/tests/config/require-prettier.js",
7272
"prettier-standalone": "<rootDir>/tests/config/require-standalone.js",
7373
},
74-
modulePathIgnorePatterns: ["<rootDir>/dist", "<rootDir>/website"],
74+
modulePathIgnorePatterns: [
75+
"<rootDir>/dist",
76+
"<rootDir>/website",
77+
"<rootDir>/scripts/release",
78+
],
7579
transform,
7680
watchPlugins: [
7781
"jest-watch-typeahead/filename",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"@rollup/plugin-node-resolve": "13.0.4",
9999
"@rollup/plugin-replace": "3.0.0",
100100
"@types/estree": "0.0.50",
101+
"@types/jest": "27.0.1",
101102
"babel-jest": "27.1.0",
102103
"babel-loader": "8.2.2",
103104
"benchmark": "2.1.4",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import chalk from "chalk";
2+
import step from "../../steps/validate-new-version.js";
3+
4+
describe("validate-new-version", () => {
5+
it("throws error for invalid semver", () => {
6+
expect(() => {
7+
step({ version: "foo" });
8+
}).toThrow("Invalid version specified");
9+
});
10+
it("throws error when version isn't greater than prev version", () => {
11+
expect(() => {
12+
step({ version: "0.0.1", previousVersion: "0.0.2" });
13+
}).toThrow(`Version ${chalk.yellow("0.0.1")} has already been published`);
14+
});
15+
});

scripts/release/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"private": true,
33
"type": "module",
4+
"scripts": {
5+
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
6+
},
47
"dependencies": {
58
"chalk": "4.1.2",
69
"execa": "5.1.1",
@@ -9,5 +12,8 @@
912
"outdent": "0.8.0",
1013
"semver": "7.3.5",
1114
"string-width": "5.0.0"
15+
},
16+
"devDependencies": {
17+
"jest": "27.1.0"
1218
}
1319
}

0 commit comments

Comments
 (0)