Skip to content

ci: add e2e tests to CI #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
test:
name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
name: Test / Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -67,3 +67,47 @@ jobs:
node-version: 'lts/*'
- run: npm install
- run: npm run typecheck

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- run: npm install
- run: npm run build
- name: Upload build results
uses: actions/upload-artifact@v4
with:
name: build_dist
path: dist
e2e:
name: E2E / Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version:
- '24.0.0' # minimum supported v24
- 24
- '22.13.1' # minimum supported v22
- 22
- '20.19.0' #minimum supported v20
- 20
os:
- ubuntu-latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we may be missing tests on Windows. Should we test that here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can add that. Do you want it added to the unit test matrix too?

Copy link
Contributor Author

@michaelfaith michaelfaith Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the e2e job. If you want me to add it to the test job, I can do that too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally would be good to test on both. Hopefully it doesn't hurt perf too much. Also could be done separately.

- windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Download build results
uses: actions/download-artifact@v4
with:
name: build_dist
path: dist
- run: npm install
- run: npm run e2e
1 change: 1 addition & 0 deletions .npmpackagejsonlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e2e/
1 change: 1 addition & 0 deletions e2e/all-typed-config/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock = false
15 changes: 15 additions & 0 deletions e2e/all-typed-config/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'eslint/config';

import eslintPlugin from 'eslint-plugin-eslint-plugin';

export default defineConfig([
{
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
},
{
extends: [eslintPlugin.configs.all],
files: ['./index.js', './rule.js'],
},
]);
25 changes: 25 additions & 0 deletions e2e/all-typed-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import rule from './rule.js';

/** @type {import('eslint').ESLint.Plugin} */
const plugin = {
meta: {
name: '@e2e/all-typed-config',
version: '1.0.0',
},
rules: { 'e2e-test': rule },
configs: {
recommended: {
name: '@e2e/all-typed-config/recommended',
plugins: {
get ['@e2e/all-typed-config']() {
return plugin;
},
},
rules: {
'@e2e/all-typed-config/e2e-test': 'error',
},
},
},
};

export default plugin;
15 changes: 15 additions & 0 deletions e2e/all-typed-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@e2e/all-typed-config",
"private": true,
"type": "module",
"scripts": {
"lint": "tsc && eslint"
},
"main": "./index.js",
"devDependencies": {
"eslint": "^9.33.0",
"eslint-plugin-eslint-plugin": "file:../..",
"jiti": "^2.5.1",
"typescript": "^5.9.2"
}
}
32 changes: 32 additions & 0 deletions e2e/all-typed-config/rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @type {import('eslint').Rule.RuleModule} */
const rule = {
// eslint-disable-next-line eslint-plugin/require-meta-schema
meta: {
type: 'suggestion',
docs: {
description: 'enforce a test',
recommended: false,
url: 'https://test.org',
},
fixable: undefined, // or "code" or "whitespace"
messages: {
missingOutput: 'This is a test',
},
},

create(context) {
return {
Program(ast) {
const sourceCode = context.sourceCode;
if (false) {
context.report({
node: ast,
messageId: 'missingOutput',
});
}
},
};
},
};

export default rule;
15 changes: 15 additions & 0 deletions e2e/all-typed-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"rootDir": ".",
"module": "nodenext",
"moduleResolution": "nodenext",
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2024",
"verbatimModuleSyntax": true,
"erasableSyntaxOnly": true,
"types": []
},
"include": ["eslint.config.ts"]
}
1 change: 1 addition & 0 deletions e2e/all/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock = false
15 changes: 15 additions & 0 deletions e2e/all/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'eslint/config';

import eslintPlugin from 'eslint-plugin-eslint-plugin';

export default defineConfig([
{
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
},
{
extends: [eslintPlugin.configs.all],
files: ['./index.js', './rule.js'],
},
]);
25 changes: 25 additions & 0 deletions e2e/all/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import rule from './rule.js';

/** @type {import('eslint').ESLint.Plugin} */
const plugin = {
meta: {
name: '@e2e/all',
version: '1.0.0',
},
rules: { 'e2e-test': rule },
configs: {
recommended: {
name: '@e2e/all/recommended',
plugins: {
get ['@e2e/all']() {
return plugin;
},
},
rules: {
'@e2e/all/e2e-test': 'error',
},
},
},
};

export default plugin;
13 changes: 13 additions & 0 deletions e2e/all/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@e2e/all",
"private": true,
"type": "module",
"scripts": {
"lint": "eslint"
},
"main": "./index.js",
"devDependencies": {
"eslint": "^9.33.0",
"eslint-plugin-eslint-plugin": "file:../.."
}
}
32 changes: 32 additions & 0 deletions e2e/all/rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @type {import('eslint').Rule.RuleModule} */
const rule = {
// eslint-disable-next-line eslint-plugin/require-meta-schema
meta: {
type: 'suggestion',
docs: {
description: 'enforce a test',
recommended: false,
url: 'https://test.org',
},
fixable: undefined, // or "code" or "whitespace"
messages: {
missingOutput: 'This is a test',
},
},

create(context) {
return {
Program(ast) {
const sourceCode = context.sourceCode;
if (false) {
context.report({
node: ast,
messageId: 'missingOutput',
});
}
},
};
},
};

export default rule;
63 changes: 63 additions & 0 deletions e2e/runAllTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs/promises';
import path from 'node:path';
import process from 'node:process';

/**
* Run All Tests: This script executes the lint command on all subfolders under `fixtures`, in order
* to validate the correctness of our plugin. Each fixture installs the *built* package. So this should
* only be run after a build has been done.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, how is the performance impact of this on our builds?

Copy link
Contributor Author

@michaelfaith michaelfaith Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In total, it adds around 40s to a minute to the overall CI runtime. Mainly because the E2E steps have to wait for the build to complete. Just looking at the build readout below, it took 38s for the build job, which ran in parallel to all of the other existing jobs. At that point all the E2E jobs kicked off in parallel, and the longest running of those are the windows ones, which took about a minute each (the ubuntu ones took between 40-50s).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RE: performance, though, there will be a roughly linear impact to the length of those steps, for each e2e test that's added in the future. So, one thing to consider, if many more are added, would be to run some number of them concurrently. I wouldn't necessarily go to that right now, because it adds some amount of complexity. With just two tests, there's not much to gain with doing them concurrently. But if there were 10 or more, it might start to make sense.

*
* For each directory under fixtures, the script runs `npm install` and `npm run lint`.
*/

const TEST_COMMAND = 'npm run lint';

const getRoot = () => {
return execSync('git rev-parse --show-toplevel', {
encoding: 'utf-8',
}).trim();
};

const executeAllE2eTests = async () => {
const e2eDir = path.resolve(getRoot(), './e2e');
const failedTests = [];

// Get all directories in the e2e dir
const testDirs = (await fs.readdir(e2eDir, { withFileTypes: true }))
.filter((dirEnt) => dirEnt.isDirectory())
.map((dirEnt) => path.join(dirEnt.parentPath, dirEnt.name));

for (const testDir of testDirs) {
const dirName = path.basename(testDir);
console.log(`🧪 Executing test: ${dirName}`);

// Run install and the test command
execSync('npm install', {
cwd: testDir,
stdio: ['ignore', 'ignore', 'pipe'],
});
try {
execSync(TEST_COMMAND, {
cwd: testDir,
stdio: 'inherit',
});
console.log(`✅ Test passed`);
} catch (error) {
console.log(`❌ Test failed`);
failedTests.push(dirName);
}
console.log(`\n${'-'.repeat(50)}\n`);
}

if (failedTests.length) {
console.log(
`Testing complete. ${failedTests.length} of ${testDirs.length} tests failed!`,
);
process.exitCode = 1;
} else {
console.log(`Testing complete. All ${testDirs.length} tests passed!`);
}
};

executeAllE2eTests();
2 changes: 1 addition & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const compat = new FlatCompat({
export default tseslint.config([
// Global ignores
{
ignores: ['node_modules', 'coverage', 'dist', 'tests/lib/fixtures'],
ignores: ['node_modules', 'coverage', 'dist', 'tests/lib/fixtures', 'e2e'],
},
// Global settings
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"license": "MIT",
"scripts": {
"build": "tsdown",
"e2e": "node ./e2e/runAllTests.js",
"format": "prettier --write .",
"format:check": "prettier --check .",
"lint": "npm-run-all --continue-on-error --aggregate-output --parallel lint:*",
Expand Down
Loading