Skip to content

Commit

Permalink
ci: rework compiling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Jul 15, 2023
1 parent 1e07a9f commit e428ddd
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 34 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
"parserOptions": {
"project": ["./tsconfig.json"]
},
"ignorePatterns": ["/build/", "/coverage/", "/lib/", "/cz-adapter/**/*.js"],
"ignorePatterns": [
"/build/",
"/coverage/",
"/lib/",
"/tests-compiled/",
"/cz-adapter/**/*.js"
],
"rules": {
"functional/prefer-immutable-types": "off",
"@typescript-eslint/no-explicit-any": "warn",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/lib/
/build/
/coverage/
/tests-compiled/

.nyc_output/

Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/lib/
/build/
/coverage/
/tests-compiled/

.nyc_output/

Expand Down
6 changes: 2 additions & 4 deletions ava.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ function getBoolean(value) {
: Boolean(asNumber);
}

const testAllFiles = getBoolean(process.env["TEST_ALL_FILES"]);
const useCompiledTests = getBoolean(process.env["USE_COMPILED_TESTS"]);
const onlyTestWorkFile = getBoolean(process.env["ONLY_TEST_WORK_FILE"]);

const avaCommonConfig = {
files: testAllFiles
? ["tests/rules/*.test.*"]
: onlyTestWorkFile
files: onlyTestWorkFile
? ["tests/rules/work.test.*"]
: ["tests/**/!(work)*.test.*"],
timeout: "5m",
Expand All @@ -33,6 +30,7 @@ const avaTsConfig = {

const avaJsConfig = {
...avaCommonConfig,
files: avaCommonConfig.files.map((file) => `tests-compiled/${file}`),
};

export default useCompiledTests ? avaJsConfig : avaTsConfig;
3 changes: 2 additions & 1 deletion knip.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"entry": ["src/index.ts!", "tests/**/*.test.ts", "cz-adapter/index.ts"],
"project": ["src/**/*.ts!", "tests/**/*.ts", "cz-adapter/**/*.ts"],
"ignoreDependencies": [
"@typescript-eslint/eslint-plugin-disable-type-checked"
"@typescript-eslint/eslint-plugin-disable-type-checked",
"glob"
],
"ignore": ["tests/fixture/file.ts"]
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"scripts": {
"build": "pnpm run build:node && pnpm run build:docs",
"build-tests": "rimraf build && node --no-warnings=ExperimentalWarning --loader=ts-paths-esm-loader/transpile-only --experimental-specifier-resolution=node scripts/compile-tests.mts",
"build-tests": "rimraf tests-compiled && rollup -c rollup.config.tests.ts --configPlugin @rollup/plugin-typescript",
"build:docs": "eslint-doc-generator",
"build:node": "rimraf lib && rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript",
"cz": "git-cz",
Expand Down Expand Up @@ -128,6 +128,7 @@
"eslint-plugin-sonarjs": "0.19.0",
"eslint-plugin-unicorn": "48.0.0",
"espree": "9.6.1",
"glob": "^10.3.3",
"husky": "8.0.3",
"knip": "2.15.5",
"lint-staged": "13.2.3",
Expand All @@ -140,8 +141,6 @@
"rollup-plugin-auto-external": "2.0.0",
"semantic-release": "21.0.7",
"ts-node": "10.9.1",
"ts-paths-esm-loader": "^1.4.3",
"tsc-prog": "2.2.1",
"tsconfig-paths": "4.2.0",
"tslib": "2.6.0",
"typescript": "5.1.6",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

38 changes: 38 additions & 0 deletions rollup.config.tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import rollupPluginCommonjs from "@rollup/plugin-commonjs";
import rollupPluginJSON from "@rollup/plugin-json";
import rollupPluginTypescript from "@rollup/plugin-typescript";
import { glob } from "glob";
import { defineConfig } from "rollup";
import rollupPluginAutoExternal from "rollup-plugin-auto-external";

const testFiles = await glob("./tests/**/*.test.ts");

export default defineConfig({
input: Object.fromEntries(testFiles.map((file) => [file, file])),

output: [
{
sourcemap: false,
dir: "tests-compiled",
format: "cjs",
},
],

plugins: [
rollupPluginAutoExternal(),
rollupPluginCommonjs(),
rollupPluginTypescript(),
rollupPluginJSON({
preferConst: true,
}),
],

external: [],

treeshake: {
annotations: true,
moduleSideEffects: [],
propertyReadSideEffects: false,
unknownGlobalSideEffects: false,
},
});
5 changes: 0 additions & 5 deletions scripts/.eslintrc.json

This file was deleted.

19 changes: 0 additions & 19 deletions scripts/compile-tests.mts

This file was deleted.

2 changes: 1 addition & 1 deletion tests/helpers/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "node:path";

import { type RuleTesterConfig } from "@typescript-eslint/rule-tester";

const fixturePath = path.join(__dirname, "../fixture");
const fixturePath = path.join(process.cwd(), "tests/fixture");
export const filename = path.join(fixturePath, "file.ts");

const typescriptParser = require.resolve("@typescript-eslint/parser");
Expand Down

0 comments on commit e428ddd

Please sign in to comment.