Skip to content

Commit

Permalink
Add tests for release script (#11454)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sosukesuzuki committed Sep 7, 2021
1 parent 2bbe331 commit bf2a24f
Show file tree
Hide file tree
Showing 8 changed files with 2,520 additions and 89 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -153,6 +153,7 @@ module.exports = {
"tests/format/**/jsfmt.spec.js",
"tests/config/**/*.js",
"tests/integration/**/*.js",
"scripts/release/__tests__/**/*.spec.js",
],
env: {
jest: true,
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/release-script-test.yml
@@ -0,0 +1,35 @@
name: Release_Script_Test

defaults:
run:
working-directory: scripts/release

on:
push:
paths:
- "scripts/release/**"
- ".github/workflows/release-script-test.yml"
pull_request:
paths:
- "scripts/release/**"
- ".github/workflows/release-script-test.yml"

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Setup Node.js
uses: actions/setup-node@v2.4.0
with:
version: "14"
cache: "yarn"

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Test
run: yarn test
6 changes: 5 additions & 1 deletion jest.config.js
Expand Up @@ -71,7 +71,11 @@ module.exports = {
"prettier-local": "<rootDir>/tests/config/require-prettier.js",
"prettier-standalone": "<rootDir>/tests/config/require-standalone.js",
},
modulePathIgnorePatterns: ["<rootDir>/dist", "<rootDir>/website"],
modulePathIgnorePatterns: [
"<rootDir>/dist",
"<rootDir>/website",
"<rootDir>/scripts/release",
],
transform,
watchPlugins: [
"jest-watch-typeahead/filename",
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -98,6 +98,7 @@
"@rollup/plugin-node-resolve": "13.0.4",
"@rollup/plugin-replace": "3.0.0",
"@types/estree": "0.0.50",
"@types/jest": "27.0.1",
"babel-jest": "27.1.0",
"babel-loader": "8.2.2",
"benchmark": "2.1.4",
Expand Down
15 changes: 15 additions & 0 deletions scripts/release/__tests__/steps/validate-new-version.spec.js
@@ -0,0 +1,15 @@
import chalk from "chalk";
import step from "../../steps/validate-new-version.js";

describe("validate-new-version", () => {
it("throws error for invalid semver", () => {
expect(() => {
step({ version: "foo" });
}).toThrow("Invalid version specified");
});
it("throws error when version isn't greater than prev version", () => {
expect(() => {
step({ version: "0.0.1", previousVersion: "0.0.2" });
}).toThrow(`Version ${chalk.yellow("0.0.1")} has already been published`);
});
});
6 changes: 6 additions & 0 deletions scripts/release/package.json
@@ -1,6 +1,9 @@
{
"private": true,
"type": "module",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
},
"dependencies": {
"chalk": "4.1.2",
"execa": "5.1.1",
Expand All @@ -9,5 +12,8 @@
"outdent": "0.8.0",
"semver": "7.3.5",
"string-width": "5.0.0"
},
"devDependencies": {
"jest": "27.1.0"
}
}

0 comments on commit bf2a24f

Please sign in to comment.