Skip to content

Commit 40fd25d

Browse files
committed
test: split e2e and unit cases
close #412
1 parent 990805c commit 40fd25d

File tree

178 files changed

+511
-122
lines changed

Some content is hidden

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

178 files changed

+511
-122
lines changed

.env.yarn

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
CONFIG_PREFER_PRETTIER=1
2-
NODE_OPTIONS="--no-warnings=ESLintRCWarning"

.lintstagedrc.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
export { default } from '@1stg/lint-staged/tsc'
1+
import base from '@1stg/lint-staged/tsc'
2+
3+
export default {
4+
...base,
5+
'tests/e2e/absoluteAlias/**/*.ts?(x)': () =>
6+
'tsc -p tests/e2e/absoluteAlias --noEmit',
7+
}

.prettierignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.yarn
2+
/auto-imports.d.ts
23
/pnpm-lock.yaml
3-
/tests/pnp/.pnp.*
4-
**/*.svg
4+
.pnp.*
5+
*.svg

.vscode/settings.json

-3
This file was deleted.

auto-imports.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable */
2+
/* prettier-ignore */
3+
// @ts-nocheck
4+
// noinspection JSUnusedGlobalSymbols
5+
// Generated by unplugin-auto-import
6+
// biome-ignore lint: disable
7+
export {}
8+
declare global {
9+
const afterAll: typeof import('vitest')['afterAll']
10+
const afterEach: typeof import('vitest')['afterEach']
11+
const assert: typeof import('vitest')['assert']
12+
const beforeAll: typeof import('vitest')['beforeAll']
13+
const beforeEach: typeof import('vitest')['beforeEach']
14+
const chai: typeof import('vitest')['chai']
15+
const describe: typeof import('vitest')['describe']
16+
const expect: typeof import('vitest')['expect']
17+
const it: typeof import('vitest')['it']
18+
const suite: typeof import('vitest')['suite']
19+
const test: typeof import('vitest')['test']
20+
const vi: typeof import('vitest')['vi']
21+
const vitest: typeof import('vitest')['vitest']
22+
}

eslint.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22

3-
import recommended from '@1stg/eslint-config'
3+
import base from '@1stg/eslint-config'
44

55
/**
66
* @import {TSESLint} from '@typescript-eslint/utils'
@@ -10,7 +10,7 @@ const config = [
1010
{
1111
ignores: ['tests'],
1212
},
13-
...recommended,
13+
...base,
1414
{
1515
files: ['dummy.js/*'],
1616
languageOptions: {

package.json

+4-19
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,13 @@
5454
"build": "run-p -c 'build:*'",
5555
"build:r": "r -f cjs",
5656
"build:ts": "tsc -b",
57-
"eslint": "ESLINT_USE_FLAT_CONFIG=false eslint",
5857
"format": "prettier --write .",
5958
"lint": "run-p 'lint:*'",
6059
"lint:es": "eslint . --cache",
6160
"lint:tsc": "tsc -b --noEmit",
62-
"prepare": "simple-git-hooks && yarn-berry-deduplicate && cd tests/nestedPackageJson && yarn || exit 0",
61+
"prepare": "simple-git-hooks && yarn-berry-deduplicate || exit 0",
6362
"release": "clean-pkg-json && changeset publish",
64-
"test": "run-p 'test:*'",
65-
"test:absoluteAlias": "yarn eslint --ext ts,tsx tests/absoluteAlias",
66-
"test:dotInclude": "yarn eslint --ext ts,tsx tests/dotInclude --ignore-pattern \"!.dot\"",
67-
"test:dotPaths": "yarn eslint --ext ts,tsx tests/dotPaths --ignore-pattern \"!.dot\"",
68-
"test:dotProject": "yarn eslint --ext ts,tsx tests/dotProject --ignore-pattern \"!.dot\"",
69-
"test:importXResolverV3": "eslint --config=tests/importXResolverV3/eslint.config.cjs tests/importXResolverV3",
70-
"test:multipleEslintrcs": "yarn eslint --ext ts,tsx tests/multipleEslintrcs",
71-
"test:multipleTsconfigs": "yarn eslint --ext ts,tsx tests/multipleTsconfigs",
72-
"test:nearestTsconfig": "yarn eslint --ext ts,tsx tests/nearestTsconfig",
73-
"test:nestedPackageJson": "yarn eslint --ext ts,tsx tests/nestedPackageJson",
74-
"test:unit": "vitest --run",
75-
"test:withJsExtension": "node tests/withJsExtension/test.js && yarn eslint --ext ts,tsx tests/withJsExtension",
76-
"test:withJsconfig": "yarn eslint --ext js tests/withJsconfig",
77-
"test:withPaths": "yarn eslint --ext ts,tsx tests/withPaths",
78-
"test:withPathsAndNestedBaseUrl": "yarn eslint --ext ts,tsx tests/withPathsAndNestedBaseUrl",
79-
"test:withQuerystring": "yarn eslint --ext ts,tsx tests/withQuerystring",
80-
"test:withoutPaths": "yarn eslint --ext ts,tsx tests/withoutPaths",
63+
"test": "node tests/e2e/withJsExtension/test.cjs && vitest run",
8164
"typecov": "type-coverage"
8265
},
8366
"peerDependencies": {
@@ -107,6 +90,7 @@
10790
"@changesets/cli": "^2.28.1",
10891
"@commitlint/cli": "^19.8.0",
10992
"@mozilla/glean": "^5.0.3",
93+
"@pkgr/core": "^0.2.0",
11094
"@pkgr/rollup": "^6.0.1",
11195
"@total-typescript/ts-reset": "^0.6.1",
11296
"@types/debug": "^4.1.12",
@@ -130,6 +114,7 @@
130114
"tinyexec": "^1.0.1",
131115
"type-coverage": "^2.29.7",
132116
"typescript": "~5.8.2",
117+
"unplugin-auto-import": "^19.1.2",
133118
"vitest": "^3.0.9",
134119
"yarn-berry-deduplicate": "^6.1.1"
135120
},
+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`e2e cases > should exec eslint successfully > absoluteAlias 1`] = `
4+
{
5+
"exitCode": 0,
6+
"stderr": "",
7+
"stdout": "",
8+
}
9+
`;
10+
11+
exports[`e2e cases > should exec eslint successfully > dotInclude 1`] = `
12+
{
13+
"exitCode": 0,
14+
"stderr": "",
15+
"stdout": "",
16+
}
17+
`;
18+
19+
exports[`e2e cases > should exec eslint successfully > dotPaths 1`] = `
20+
{
21+
"exitCode": 0,
22+
"stderr": "",
23+
"stdout": "",
24+
}
25+
`;
26+
27+
exports[`e2e cases > should exec eslint successfully > dotProject 1`] = `
28+
{
29+
"exitCode": 0,
30+
"stderr": "",
31+
"stdout": "",
32+
}
33+
`;
34+
35+
exports[`e2e cases > should exec eslint successfully > importXResolverV3 1`] = `
36+
{
37+
"exitCode": 0,
38+
"stderr": "",
39+
"stdout": "",
40+
}
41+
`;
42+
43+
exports[`e2e cases > should exec eslint successfully > multipleEslintrcs 1`] = `
44+
{
45+
"exitCode": 0,
46+
"stderr": "",
47+
"stdout": "",
48+
}
49+
`;
50+
51+
exports[`e2e cases > should exec eslint successfully > multipleTsconfigs 1`] = `
52+
{
53+
"exitCode": 0,
54+
"stderr": "",
55+
"stdout": "",
56+
}
57+
`;
58+
59+
exports[`e2e cases > should exec eslint successfully > nearestTsconfig 1`] = `
60+
{
61+
"exitCode": 0,
62+
"stderr": "",
63+
"stdout": "",
64+
}
65+
`;
66+
67+
exports[`e2e cases > should exec eslint successfully > nestedPackageJson 1`] = `
68+
{
69+
"exitCode": 0,
70+
"stderr": "",
71+
"stdout": "",
72+
}
73+
`;
74+
75+
exports[`e2e cases > should exec eslint successfully > withJsExtension 1`] = `
76+
{
77+
"exitCode": 0,
78+
"stderr": "",
79+
"stdout": "",
80+
}
81+
`;
82+
83+
exports[`e2e cases > should exec eslint successfully > withJsconfig 1`] = `
84+
{
85+
"exitCode": 0,
86+
"stderr": "",
87+
"stdout": "",
88+
}
89+
`;
90+
91+
exports[`e2e cases > should exec eslint successfully > withPaths 1`] = `
92+
{
93+
"exitCode": 0,
94+
"stderr": "",
95+
"stdout": "",
96+
}
97+
`;
98+
99+
exports[`e2e cases > should exec eslint successfully > withPathsAndNestedBaseUrl 1`] = `
100+
{
101+
"exitCode": 0,
102+
"stderr": "",
103+
"stdout": "",
104+
}
105+
`;
106+
107+
exports[`e2e cases > should exec eslint successfully > withQuerystring 1`] = `
108+
{
109+
"exitCode": 0,
110+
"stderr": "",
111+
"stdout": "",
112+
}
113+
`;
114+
115+
exports[`e2e cases > should exec eslint successfully > withoutPaths 1`] = `
116+
{
117+
"exitCode": 0,
118+
"stderr": "",
119+
"stdout": "",
120+
}
121+
`;
File renamed without changes.

tests/absoluteAlias/tsconfig.json renamed to tests/e2e/absoluteAlias/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"extends": "../../../tsconfig.base",
23
"compilerOptions": {
34
"paths": {
45
"/*": ["./public/*"]

tests/base.eslintrc.cjs renamed to tests/e2e/base.eslintrc.cjs

+10-3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ const base = project => ({
3232
tsx: 'never',
3333
},
3434
],
35-
'node/no-extraneous-import': 0,
36-
'node/no-missing-import': 0,
35+
'import-x/order': [
36+
2,
37+
{
38+
alphabetize: {
39+
order: 'asc',
40+
},
41+
'newlines-between': 'always',
42+
},
43+
],
3744
},
3845
overrides: [
3946
{
40-
files: '**/.*.cjs',
47+
files: '**/*.{cjs,cts}',
4148
env: {
4249
node: true,
4350
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/e2e/e2e.spec.ts

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
4+
import { tryFile } from '@pkgr/core'
5+
import { exec } from 'tinyexec'
6+
7+
describe('e2e cases', async () => {
8+
const { dirname } = import.meta
9+
10+
const dirents = await fs.readdir(dirname, { withFileTypes: true })
11+
12+
for (const dirent of dirents) {
13+
const dirName = dirent.name
14+
15+
if (!dirent.isDirectory() || dirName === '__snapshots__') {
16+
continue
17+
}
18+
19+
const absoluteDir = path.resolve(dirname, dirName)
20+
21+
if (tryFile('yarn.lock', false, absoluteDir)) {
22+
await exec('yarn', ['--immutable'], {
23+
nodeOptions: {
24+
cwd: absoluteDir,
25+
},
26+
})
27+
}
28+
29+
it('should exec eslint successfully', async () => {
30+
const eslintConfig = tryFile('eslint.config.js', false, absoluteDir)
31+
expect(
32+
await exec(
33+
'yarn',
34+
[
35+
'eslint',
36+
...(eslintConfig
37+
? ['-c', eslintConfig]
38+
: ['--ignore-pattern', '!.dot']),
39+
'--ext',
40+
'cjs,cts,js,jsx,mjs,mts,ts,tsx',
41+
'--report-unused-disable-directives',
42+
absoluteDir,
43+
],
44+
{
45+
nodeOptions: {
46+
env: {
47+
ESLINT_USE_FLAT_CONFIG: eslintConfig ? undefined : 'false',
48+
NODE_OPTIONS: '--no-warnings=ESLintRCWarning',
49+
},
50+
},
51+
},
52+
),
53+
).toMatchSnapshot(dirName)
54+
})
55+
}
56+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import path from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
4+
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
5+
import importX, { flatConfigs } from 'eslint-plugin-import-x'
6+
7+
import base from '../base.eslintrc.cjs'
8+
9+
const globPattern = './packages/*/tsconfig.json'
10+
11+
// in normal cases this is not needed because the `dirname` would be the root
12+
const absoluteGlobPath = path.resolve(
13+
fileURLToPath(import.meta.url),
14+
'..',
15+
globPattern,
16+
)
17+
18+
export default +process.versions.node.split('.')[0] <= 16
19+
? {}
20+
: {
21+
files: ['**/*.ts', '**/*.tsx'],
22+
plugins: {
23+
'import-x': importX,
24+
},
25+
settings: {
26+
...flatConfigs.typescript.settings,
27+
'import-x/resolver-next': [
28+
createTypeScriptImportResolver({
29+
project: absoluteGlobPath,
30+
noWarnOnMultipleProjects: true,
31+
}),
32+
],
33+
},
34+
rules: base().rules,
35+
}
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"type": "commonjs",
2+
"type": "module",
33
"private": true
44
}

tests/withJsExtension/.eslintrc.cjs renamed to tests/e2e/withJsExtension/.eslintrc.cjs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-env node */
21
const config = require('../base.eslintrc.cjs')(__dirname)
32

43
module.exports = {

tests/withJsExtension/index.ts renamed to tests/e2e/withJsExtension/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// import relative
22
import './tsImportee.js'
3+
import './tsxImportee.js'
34
import './tsxImportee.jsx'
45
import './dtsImportee.js'
56
import './dtsImportee.jsx'

tests/withJsExtension/test.js renamed to tests/e2e/withJsExtension/test.cjs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
/* eslint-env node */
2-
/* eslint-disable @typescript-eslint/no-var-requires */
1+
const assert = require('node:assert')
2+
const path = require('node:path')
33

4-
const path = require('path')
5-
const assert = require('assert')
6-
7-
const { resolve } = require('../../')
4+
const { resolve } = require('../../..')
85

96
const config = {
107
project: path.join(__dirname, 'tsconfig.json'),
@@ -128,4 +125,4 @@ assertResolve(
128125
)
129126

130127
// resolves symlinks by default
131-
assertResolve('dummy.js', '../../dummy.js/index.js')
128+
assertResolve('dummy.js', '../../../dummy.js/index.js')
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../base.eslintrc.cjs')(__dirname)
File renamed without changes.
File renamed without changes.

tests/e2e/withoutPaths/.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../base.eslintrc.cjs')(__dirname)
File renamed without changes.

0 commit comments

Comments
 (0)