From 63294b268bd7be3c0e6695c255a6c5f3214080b5 Mon Sep 17 00:00:00 2001 From: Misha Kaletsky Date: Sun, 26 Jan 2025 16:29:21 +0800 Subject: [PATCH] snapshot instead (updated 16:36) --- test/__snapshots__/mmkal-repos.test.ts.snap | 50 +++++++++++++++++++++ test/mmkal-repos.test.ts | 19 ++++++-- 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 test/__snapshots__/mmkal-repos.test.ts.snap diff --git a/test/__snapshots__/mmkal-repos.test.ts.snap b/test/__snapshots__/mmkal-repos.test.ts.snap new file mode 100644 index 00000000..28003f11 --- /dev/null +++ b/test/__snapshots__/mmkal-repos.test.ts.snap @@ -0,0 +1,50 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`lint https://github.com/mmkal/expect-type 1`] = ` +" +> expect-type@1.1.0 eslint
/expect-type +> eslint --max-warnings 0 "." "--fix" "--max-warnings" "0" + + +
/expect-type/src/branding.ts + : error The \`Function\` type accepts any function-like value. +Prefer explicitly defining any function parameters and return type @typescript-eslint/no-unsafe-function-type + +
/expect-type/src/index.ts + : error The \`Function\` type accepts any function-like value. +Prefer explicitly defining any function parameters and return type @typescript-eslint/no-unsafe-function-type + +
/expect-type/src/utils.ts + : error 'secret' is assigned a value but only used as a type. Allowed unused vars must match /^_/u @typescript-eslint/no-unused-vars + +
/expect-type/test/ts-output.ts + : warning Use default import for module \`node:path\` unicorn/import-style + +
/expect-type/test/types.test.ts + : error Expected an assignment or function call and instead saw an expression @typescript-eslint/no-unused-expressions + : error Expected an assignment or function call and instead saw an expression @typescript-eslint/no-unused-expressions + +
/expect-type/test/usage.test.ts + : error 'A' is defined but only used as a type. Allowed unused vars must match /^_/u @typescript-eslint/no-unused-vars + : error 'B' is defined but only used as a type. Allowed unused vars must match /^_/u @typescript-eslint/no-unused-vars + : error 'C' is defined but only used as a type. Allowed unused vars must match /^_/u @typescript-eslint/no-unused-vars + +✖ 9 problems (8 errors, 1 warning) + + ELIFECYCLE  Command failed with exit code 1." +`; + +exports[`lint https://github.com/mmkal/trpc-cli 1`] = ` +" +
/trpc-cli/src/index.ts + : error The \`Function\` type accepts any function-like value. +Prefer explicitly defining any function parameters and return type @typescript-eslint/no-unsafe-function-type + : error Expected an error object to be thrown @typescript-eslint/only-throw-error + +
/trpc-cli/src/util.ts + : error The \`Function\` type accepts any function-like value. +Prefer explicitly defining any function parameters and return type @typescript-eslint/no-unsafe-function-type + +✖ 3 problems (3 errors, 0 warnings) +" +`; diff --git a/test/mmkal-repos.test.ts b/test/mmkal-repos.test.ts index 89a8adb5..935f86f1 100644 --- a/test/mmkal-repos.test.ts +++ b/test/mmkal-repos.test.ts @@ -7,23 +7,34 @@ const reposToTest = [ 'https://github.com/mmkal/trpc-cli', ] +const ts = Date.now().toString() + for (const repo of reposToTest) { test( `lint ${repo}`, async () => { const {execa} = await import('execa') await execa('pnpm', ['build']) - const tmp = path.join(`/tmp/eslint-plugin-mmkal-testing`, Date.now().toString()) + const tmp = path.join(`/tmp/eslint-plugin-mmkal-testing`, ts) fs.mkdirSync(tmp, {recursive: true}) await execa('git', ['clone', repo], {cwd: tmp}) - const [cloneName, ...otherFiles] = fs.readdirSync(tmp) + const [cloneName, ...otherFiles] = fs.readdirSync(tmp).filter(f => f === repo.split('/').pop()) const clone = path.join(tmp, cloneName) expect(otherFiles).toEqual([]) await execa('pnpm', ['install'], {cwd: clone}) await execa(path.join(process.cwd(), 'node_modules', '.bin', 'link'), [process.cwd()], {cwd: clone}) - const {all: lint} = await execa('pnpm', ['eslint', '.', '--fix', '--max-warnings', '0'], {cwd: clone}) + const {all: lint} = await execa('pnpm', ['eslint', '.', '--fix', '--max-warnings', '0'], { + all: true, + cwd: clone, + reject: false, + }) - expect(lint!.toLowerCase()).not.toContain('error') + const snapshot = lint + .replaceAll(tmp, '') + .replaceAll('/private/', '/') + .replaceAll(ts, '') + .replaceAll(/\d+:\d+/g, ':') + expect(snapshot).toMatchSnapshot() }, {timeout: 30_000}, )