Skip to content

Commit b8ec006

Browse files
chore: switch testing over to ava
1 parent 2aa354e commit b8ec006

File tree

126 files changed

+5874
-7162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+5874
-7162
lines changed

.eslintrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"eslint-plugin",
77
"functional",
88
"import",
9-
"jest",
109
"jsdoc",
1110
"prettier"
1211
],
@@ -30,7 +29,7 @@
3029
"ignorePatterns": ["build/", "coverage/", "lib/"],
3130
"rules": {
3231
"@typescript-eslint/no-unnecessary-condition": "off",
33-
"import/no-unassigned-import": "off",
32+
"import/no-relative-parent-imports": "error",
3433
"node/no-unsupported-features/es-builtins": "off",
3534
"node/no-unsupported-features/es-syntax": "off",
3635
// enable once supported in all our supported node versions.

.github/workflows/ci.yml

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,18 @@ jobs:
5959
runs-on: ${{ matrix.os }}
6060
continue-on-error: ${{ matrix.ts_version == 'next' }}
6161
env:
62-
# Use compiled tests on everything instances except this one.
63-
USE_COMPILED_TEST: ${{ fromJSON('["false", "true"]')[matrix.ts_version != 'latest' || matrix.node_version != '16' || matrix.os != 'ubuntu-latest'] }}
62+
REPORT_COVERAGE: ${{ fromJSON('["false", "true"]')[matrix.ts_version == 'latest' && matrix.node_version == '16' && matrix.os != 'ubuntu-latest'] }}
6463
steps:
6564
- name: Checkout
6665
uses: actions/checkout@v2
6766
with:
6867
# Fetch all commits for codecov.
69-
fetch-depth: ${{ fromJSON('[0, 1]')[ env.USE_COMPILED_TEST == 'true'] }}
68+
fetch-depth: ${{ fromJSON('[0, 1]')[ env.REPORT_COVERAGE == 'true'] }}
7069

71-
- name: Setup NodeJs
70+
- name: Setup NodeJs for building
7271
uses: actions/setup-node@v1
7372
with:
74-
node-version: ${{ matrix.node_version }}
75-
76-
# Remove dev-dependencies that aren't needed for testing and aren't compatable with all node versions being tested against.
77-
- name: Remove unneeded incompatible dev-dependencies
78-
run: yarn remove @rebeccastevens/eslint-config
73+
node-version: "16"
7974

8075
- name: Install Dependencies
8176
run: yarn install --frozen-lockfile
@@ -84,26 +79,28 @@ jobs:
8479
run: yarn build
8580

8681
- name: Compile Tests
87-
if: env.USE_COMPILED_TEST == 'true'
82+
if: env.REPORT_COVERAGE == 'false'
8883
run: yarn compile-tests
8984

85+
- name: Setup NodeJs ${{ matrix.node_version }} for testing
86+
uses: actions/setup-node@v1
87+
with:
88+
node-version: ${{ matrix.node_version }}
89+
9090
- name: Remove Dev TypeScript
91-
run: yarn remove typescript
91+
run: yarn remove typescript --ignore-engines
9292

9393
- name: Add TypeScript "${{ matrix.ts_version }}"
9494
if: matrix.ts_version != 'JS'
95-
run: yarn add -D typescript@"${{ matrix.ts_version }}"
95+
run: yarn add -D typescript@"${{ matrix.ts_version }}" --ignore-engines
9696

97-
- name: Run Tests (Uncompiled)
98-
if: env.USE_COMPILED_TEST != 'true'
97+
- name: Run Tests
9998
run: yarn test
100-
101-
- name: Run Tests (Compiled)
102-
if: env.USE_COMPILED_TEST == 'true'
103-
run: yarn test-compiled
99+
env:
100+
USE_COMPILED_TESTS: ${{ env.REPORT_COVERAGE == 'false' }}
104101

105102
- name: Report coverage
106103
uses: codecov/codecov-action@v1
107-
if: env.USE_COMPILED_TEST != 'true'
104+
if: env.REPORT_COVERAGE == 'true'
108105
with:
109106
file: coverage/lcov.info

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.DS_Store
22
thumbs.db
33
*.log
4-
.rpt2_cache/
4+
.nyc_output/
55
node_modules/
66
/build/
77
/lib/

.nycrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "@istanbuljs/nyc-config-typescript",
3+
"include": [
4+
"src/**/*"
5+
],
6+
"exclude": [
7+
"src/util/conditional-imports/**/*"
8+
],
9+
"reporter": [
10+
"lcov",
11+
"text"
12+
],
13+
"check-coverage": false,
14+
"watermarks": {
15+
"lines": [80, 95],
16+
"functions": [80, 95],
17+
"branches": [80, 95],
18+
"statements": [80, 95]
19+
}
20+
}

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"files.exclude": {
3-
".rpt2_cache": true,
3+
".nyc_output": true,
44
"coverage": true,
55
},
66
"files.trimTrailingWhitespace": true,
77
"search.exclude": {
88
"**/.git/": true,
9-
"**/.rpt2_cache/": true,
9+
"**/.nyc_output/": true,
1010
"**/yarn.lock": true,
1111
".vscode/": true,
1212
"build/": true,

ava.config.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// @ts-check
2+
3+
/**
4+
* Get the intended boolean value from the given string.
5+
*/
6+
function getBoolean(value) {
7+
if (value === undefined) {
8+
return false;
9+
}
10+
const asNumber = Number(value);
11+
return Number.isNaN(asNumber)
12+
? Boolean(String(value).toLowerCase().replace("false", ""))
13+
: Boolean(asNumber);
14+
}
15+
16+
const useCompiledTests = getBoolean(process.env.USE_COMPILED_TESTS);
17+
18+
const avaCommonConfig = {
19+
files: ["tests/**/!(_)*.test.*"],
20+
timeout: "5m",
21+
};
22+
23+
const avaTsConfig = {
24+
...avaCommonConfig,
25+
extensions: ["ts"],
26+
require: ["ts-node/register", "tsconfig-paths/register"],
27+
environmentVariables: {
28+
TS_NODE_PROJECT: "tests/tsconfig.json",
29+
},
30+
};
31+
32+
const avaJsConfig = {
33+
...avaCommonConfig,
34+
files: avaCommonConfig.files.map((file) => `build/${file}`),
35+
extensions: ["js"],
36+
require: ["tsconfig-paths/register"],
37+
environmentVariables: {
38+
TS_NODE_PROJECT: "build/tests/tsconfig.json",
39+
},
40+
};
41+
42+
export default useCompiledTests ? avaJsConfig : avaTsConfig;

jest.config.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@
4646
"prebuild-tests": "rimraf build",
4747
"build-tests": "yarn compile-tests",
4848
"compile": "rollup -c",
49-
"compile-tests": "tsc -p tests/tsconfig.json && cpx ./tests/helpers/tsconfig.json ./build/tests/helpers/",
49+
"compile-tests": "ts-node -P scripts/tsconfig.json scripts/compile-tests.ts",
5050
"prelint": "yarn build && yarn link && yarn link 'eslint-plugin-functional'",
5151
"lint": "eslint .",
5252
"lint-fix": "yarn lint --fix",
53-
"test": "jest --testPathIgnorePatterns _work.test",
54-
"test-compiled": "cross-env USE_COMPLIED=1 yarn test",
55-
"test-work": "jest tests/rules/_work.test.ts --no-coverage",
53+
"test": "nyc ava",
54+
"test-work": "ava 'tests/rules/_work.test.ts'",
5655
"verify": "yarn build && yarn lint && yarn build-tests && yarn test-compiled && rimraf build",
5756
"preversion": "yarn verify",
5857
"version": "auto-changelog -p && git add CHANGELOG.md",
@@ -64,6 +63,7 @@
6463
"escape-string-regexp": "^4.0.0"
6564
},
6665
"devDependencies": {
66+
"@istanbuljs/nyc-config-typescript": "^1.0.1",
6767
"@rebeccastevens/eslint-config": "^1.0.10",
6868
"@rollup/plugin-commonjs": "^17.0.0",
6969
"@rollup/plugin-json": "^4.1.0",
@@ -73,24 +73,24 @@
7373
"@types/eslint": "^7.2.6",
7474
"@types/estree": "^0.0.46",
7575
"@types/glob": "^7.1.1",
76-
"@types/jest": "^26.0.19",
7776
"@types/node": "15.0.1",
7877
"@types/rollup-plugin-auto-external": "^2.0.2",
7978
"@typescript-eslint/eslint-plugin": "^4.28.4",
8079
"@typescript-eslint/parser": "^4.28.4",
8180
"auto-changelog": "^2.2.1",
81+
"ava": "^3.15.0",
8282
"babel-eslint": "^10.0.2",
8383
"codecov": "^3.8.1",
84-
"cpx": "^1.5.0",
8584
"cross-env": "^7.0.3",
8685
"dedent": "^0.7.0",
8786
"eslint": "^7.31.0",
87+
"eslint-ava-rule-tester": "^4.0.0",
8888
"eslint-config-prettier": "^8.3.0",
8989
"eslint-import-resolver-typescript": "^2.4.0",
90+
"eslint-plugin-ava": "^12.0.0",
9091
"eslint-plugin-eslint-comments": "^3.2.0",
9192
"eslint-plugin-eslint-plugin": "^3.4.0",
9293
"eslint-plugin-import": "^2.23.4",
93-
"eslint-plugin-jest": "^24.4.0",
9494
"eslint-plugin-jsdoc": "^35.5.1",
9595
"eslint-plugin-markdown": "^2.2.0",
9696
"eslint-plugin-node": "^11.1.0",
@@ -102,16 +102,17 @@
102102
"espree": "^8.0.0",
103103
"glob": "^7.1.6",
104104
"husky": "^6.0.0",
105-
"jest": "^26.6.3",
106105
"json-schema": "^0.3.0",
106+
"jsonc-parser": "^3.0.0",
107107
"lint-staged": "^10.5.3",
108+
"nyc": "^15.1.0",
108109
"prettier": "^2.2.1",
109110
"rimraf": "^3.0.0",
110111
"rollup": "^2.34.2",
111112
"rollup-plugin-auto-external": "^2.0.0",
112113
"shelljs": "^0.8.3",
113-
"ts-jest": "^26.4.4",
114114
"ts-node": "^10.1.0",
115+
"tsc-prog": "^2.2.1",
115116
"tsconfig-paths": "^3.10.1",
116117
"tslib": "^2.0.3",
117118
"typescript": "^4.1.3"

scripts/.eslintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"node/no-unsupported-features/node-builtins": "off"
4+
}
5+
}

scripts/compile-tests.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { promises as fs } from "fs";
2+
import * as JSONC from "jsonc-parser";
3+
import * as tsc from "tsc-prog";
4+
5+
/**
6+
* The script.
7+
*/
8+
async function run() {
9+
transpileTests();
10+
await Promise.all([createTestsTsConfig(), createTestsHelpersTsConfig()]);
11+
}
12+
13+
/**
14+
* Transpile the tests.
15+
*/
16+
function transpileTests() {
17+
const program = tsc.createProgramFromConfig({
18+
basePath: `${process.cwd()}/tests`,
19+
configFilePath: "tsconfig.json",
20+
});
21+
22+
tsc.emit(program, {
23+
clean: { outDir: true },
24+
});
25+
}
26+
27+
/**
28+
* Create a suitable "build/tests/tsconfig.json" file.
29+
*/
30+
async function createTestsTsConfig() {
31+
const testsTsConfig = JSONC.parse(
32+
await fs.readFile("tests/tsconfig.json", { encoding: "utf-8" })
33+
);
34+
35+
const updatedTestsTsConfig = {
36+
...testsTsConfig,
37+
extends: `../${testsTsConfig.extends}`,
38+
compilerOptions: {
39+
...testsTsConfig.compilerOptions,
40+
baseUrl: "..",
41+
},
42+
};
43+
44+
return fs.writeFile(
45+
"build/tests/tsconfig.json",
46+
JSON.stringify(updatedTestsTsConfig, null, 2),
47+
{ encoding: "utf-8" }
48+
);
49+
}
50+
51+
/**
52+
* Create a suitable "build/tests/helpers/tsconfig.json" file.
53+
*/
54+
async function createTestsHelpersTsConfig() {
55+
return fs.copyFile(
56+
"tests/helpers/tsconfig.json",
57+
"build/tests/helpers/tsconfig.json"
58+
);
59+
}
60+
61+
// Run the script.
62+
run().catch((error) => void console.error(error));

scripts/tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2018",
4+
"module": "CommonJS",
5+
"lib": ["esnext"],
6+
"alwaysStrict": true,
7+
"strict": true,
8+
"esModuleInterop": true,
9+
"moduleResolution": "node",
10+
"noImplicitAny": false,
11+
"noImplicitReturns": true,
12+
"noImplicitThis": true,
13+
"allowSyntheticDefaultImports": true,
14+
"resolveJsonModule": true,
15+
"forceConsistentCasingInFileNames": true,
16+
"importHelpers": false,
17+
"newLine": "LF",
18+
"noEmitOnError": true,
19+
"removeComments": true
20+
}
21+
}

0 commit comments

Comments
 (0)