Skip to content

test: split e2e and unit cases #421

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 1 commit into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .env.yarn
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
CONFIG_PREFER_PRETTIER=1
NODE_OPTIONS="--no-warnings=ESLintRCWarning"
8 changes: 7 additions & 1 deletion .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export { default } from '@1stg/lint-staged/tsc'
import base from '@1stg/lint-staged/tsc'

export default {
...base,
'tests/e2e/absoluteAlias/**/*.ts?(x)': () =>
'tsc -p tests/e2e/absoluteAlias --noEmit',
}
5 changes: 3 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.yarn
/auto-imports.d.ts
/pnpm-lock.yaml
/tests/pnp/.pnp.*
**/*.svg
.pnp.*
*.svg
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

22 changes: 22 additions & 0 deletions auto-imports.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// noinspection JSUnusedGlobalSymbols
// Generated by unplugin-auto-import
// biome-ignore lint: disable
export {}
declare global {
const afterAll: typeof import('vitest')['afterAll']
const afterEach: typeof import('vitest')['afterEach']
const assert: typeof import('vitest')['assert']
const beforeAll: typeof import('vitest')['beforeAll']
const beforeEach: typeof import('vitest')['beforeEach']
const chai: typeof import('vitest')['chai']
const describe: typeof import('vitest')['describe']
const expect: typeof import('vitest')['expect']
const it: typeof import('vitest')['it']
const suite: typeof import('vitest')['suite']
const test: typeof import('vitest')['test']
const vi: typeof import('vitest')['vi']
const vitest: typeof import('vitest')['vitest']
}
4 changes: 2 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check

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

/**
* @import {TSESLint} from '@typescript-eslint/utils'
Expand All @@ -10,7 +10,7 @@ const config = [
{
ignores: ['tests'],
},
...recommended,
...base,
{
files: ['dummy.js/*'],
languageOptions: {
Expand Down
23 changes: 4 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,13 @@
"build": "run-p -c 'build:*'",
"build:r": "r -f cjs",
"build:ts": "tsc -b",
"eslint": "ESLINT_USE_FLAT_CONFIG=false eslint",
"format": "prettier --write .",
"lint": "run-p 'lint:*'",
"lint:es": "eslint . --cache",
"lint:tsc": "tsc -b --noEmit",
"prepare": "simple-git-hooks && yarn-berry-deduplicate && cd tests/nestedPackageJson && yarn || exit 0",
"prepare": "simple-git-hooks && yarn-berry-deduplicate || exit 0",
"release": "clean-pkg-json && changeset publish",
"test": "run-p 'test:*'",
"test:absoluteAlias": "yarn eslint --ext ts,tsx tests/absoluteAlias",
"test:dotInclude": "yarn eslint --ext ts,tsx tests/dotInclude --ignore-pattern \"!.dot\"",
"test:dotPaths": "yarn eslint --ext ts,tsx tests/dotPaths --ignore-pattern \"!.dot\"",
"test:dotProject": "yarn eslint --ext ts,tsx tests/dotProject --ignore-pattern \"!.dot\"",
"test:importXResolverV3": "eslint --config=tests/importXResolverV3/eslint.config.cjs tests/importXResolverV3",
"test:multipleEslintrcs": "yarn eslint --ext ts,tsx tests/multipleEslintrcs",
"test:multipleTsconfigs": "yarn eslint --ext ts,tsx tests/multipleTsconfigs",
"test:nearestTsconfig": "yarn eslint --ext ts,tsx tests/nearestTsconfig",
"test:nestedPackageJson": "yarn eslint --ext ts,tsx tests/nestedPackageJson",
"test:unit": "vitest --run",
"test:withJsExtension": "node tests/withJsExtension/test.js && yarn eslint --ext ts,tsx tests/withJsExtension",
"test:withJsconfig": "yarn eslint --ext js tests/withJsconfig",
"test:withPaths": "yarn eslint --ext ts,tsx tests/withPaths",
"test:withPathsAndNestedBaseUrl": "yarn eslint --ext ts,tsx tests/withPathsAndNestedBaseUrl",
"test:withQuerystring": "yarn eslint --ext ts,tsx tests/withQuerystring",
"test:withoutPaths": "yarn eslint --ext ts,tsx tests/withoutPaths",
"test": "node tests/e2e/withJsExtension/test.cjs && vitest run",
"typecov": "type-coverage"
},
"peerDependencies": {
Expand Down Expand Up @@ -107,6 +90,7 @@
"@changesets/cli": "^2.28.1",
"@commitlint/cli": "^19.8.0",
"@mozilla/glean": "^5.0.3",
"@pkgr/core": "^0.2.0",
"@pkgr/rollup": "^6.0.1",
"@total-typescript/ts-reset": "^0.6.1",
"@types/debug": "^4.1.12",
Expand All @@ -130,6 +114,7 @@
"tinyexec": "^1.0.1",
"type-coverage": "^2.29.7",
"typescript": "~5.8.2",
"unplugin-auto-import": "^19.1.2",
"vitest": "^3.0.9",
"yarn-berry-deduplicate": "^6.1.1"
},
Expand Down
121 changes: 121 additions & 0 deletions tests/e2e/__snapshots__/e2e.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`e2e cases > should exec eslint successfully > absoluteAlias 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > dotInclude 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > dotPaths 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > dotProject 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > importXResolverV3 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > multipleEslintrcs 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > multipleTsconfigs 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > nearestTsconfig 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > nestedPackageJson 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > withJsExtension 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > withJsconfig 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > withPaths 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > withPathsAndNestedBaseUrl 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > withQuerystring 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;

exports[`e2e cases > should exec eslint successfully > withoutPaths 1`] = `
{
"exitCode": 0,
"stderr": "",
"stdout": "",
}
`;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "../../../tsconfig.base",
"compilerOptions": {
"paths": {
"/*": ["./public/*"]
Expand Down
13 changes: 10 additions & 3 deletions tests/base.eslintrc.cjs → tests/e2e/base.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ const base = project => ({
tsx: 'never',
},
],
'node/no-extraneous-import': 0,
'node/no-missing-import': 0,
'import-x/order': [
2,
{
alphabetize: {
order: 'asc',
},
'newlines-between': 'always',
},
],
},
overrides: [
{
files: '**/.*.cjs',
files: '**/*.{cjs,cts}',
env: {
node: true,
},
Expand Down
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.
56 changes: 56 additions & 0 deletions tests/e2e/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import fs from 'node:fs/promises'
import path from 'node:path'

import { tryFile } from '@pkgr/core'
import { exec } from 'tinyexec'

describe('e2e cases', async () => {
const { dirname } = import.meta

const dirents = await fs.readdir(dirname, { withFileTypes: true })

for (const dirent of dirents) {
const dirName = dirent.name

if (!dirent.isDirectory() || dirName === '__snapshots__') {
continue
}

const absoluteDir = path.resolve(dirname, dirName)

if (tryFile('yarn.lock', false, absoluteDir)) {
await exec('yarn', ['--immutable'], {
nodeOptions: {
cwd: absoluteDir,
},
})
}

it('should exec eslint successfully', async () => {
const eslintConfig = tryFile('eslint.config.js', false, absoluteDir)
expect(
await exec(
'yarn',
[
'eslint',
...(eslintConfig
? ['-c', eslintConfig]
: ['--ignore-pattern', '!.dot']),
'--ext',
'cjs,cts,js,jsx,mjs,mts,ts,tsx',
'--report-unused-disable-directives',
absoluteDir,
],
{
nodeOptions: {
env: {
ESLINT_USE_FLAT_CONFIG: eslintConfig ? undefined : 'false',
NODE_OPTIONS: '--no-warnings=ESLintRCWarning',
},
},
},
),
).toMatchSnapshot(dirName)
})
}
})
35 changes: 35 additions & 0 deletions tests/e2e/importXResolverV3/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
import importX, { flatConfigs } from 'eslint-plugin-import-x'

import base from '../base.eslintrc.cjs'

const globPattern = './packages/*/tsconfig.json'

// in normal cases this is not needed because the `dirname` would be the root
const absoluteGlobPath = path.resolve(
fileURLToPath(import.meta.url),
'..',
globPattern,
)

export default +process.versions.node.split('.')[0] <= 16
? {}
: {
files: ['**/*.ts', '**/*.tsx'],
plugins: {
'import-x': importX,
},
settings: {
...flatConfigs.typescript.settings,
'import-x/resolver-next': [
createTypeScriptImportResolver({
project: absoluteGlobPath,
noWarnOnMultipleProjects: true,
}),
],
},
rules: base().rules,
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/package.json → tests/e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "commonjs",
"type": "module",
"private": true
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-env node */
const config = require('../base.eslintrc.cjs')(__dirname)

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// import relative
import './tsImportee.js'
import './tsxImportee.js'
import './tsxImportee.jsx'
import './dtsImportee.js'
import './dtsImportee.jsx'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* eslint-env node */
/* eslint-disable @typescript-eslint/no-var-requires */
const assert = require('node:assert')
const path = require('node:path')

const path = require('path')
const assert = require('assert')

const { resolve } = require('../../')
const { resolve } = require('../../..')

const config = {
project: path.join(__dirname, 'tsconfig.json'),
Expand Down Expand Up @@ -128,4 +125,4 @@ assertResolve(
)

// resolves symlinks by default
assertResolve('dummy.js', '../../dummy.js/index.js')
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.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tests/e2e/withQuerystring/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../base.eslintrc.cjs')(__dirname)
File renamed without changes
File renamed without changes.
1 change: 1 addition & 0 deletions tests/e2e/withoutPaths/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../base.eslintrc.cjs')(__dirname)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading