-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrunner.int.test.ts
More file actions
96 lines (88 loc) · 3.36 KB
/
runner.int.test.ts
File metadata and controls
96 lines (88 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { cp } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { type MockInstance, describe, expect, it } from 'vitest';
import {
type Audit,
type AuditOutput,
type AuditOutputs,
DEFAULT_PERSIST_CONFIG,
type Issue,
} from '@code-pushup/models';
import { osAgnosticAuditOutputs } from '@code-pushup/test-fixtures';
import {
restoreNxIgnoredFiles,
teardownTestFolder,
} from '@code-pushup/test-utils';
import type { ESLintTarget } from '../config.js';
import { listAuditsAndGroups } from '../meta/list.js';
import { createRunnerFunction } from './runner.js';
describe('executeRunner', () => {
let cwdSpy: MockInstance<[], string>;
let platformSpy: MockInstance<[], NodeJS.Platform>;
const prepareRunnerArgs = async (
eslintrc: ESLintTarget['eslintrc'],
): Promise<{ audits: Audit[]; targets: ESLintTarget[] }> => {
const patterns = ['src/**/*.js', 'src/**/*.jsx'];
const targets: ESLintTarget[] = [{ eslintrc, patterns }];
const { audits } = await listAuditsAndGroups(targets);
return { audits, targets };
};
const thisDir = fileURLToPath(path.dirname(import.meta.url));
const fixturesDir = path.join(thisDir, '..', '..', '..', 'mocks', 'fixtures');
const tmpDir = path.join(process.cwd(), 'tmp', 'int', 'plugin-eslint');
const appDir = path.join(tmpDir, 'todos-app');
beforeAll(async () => {
await cp(path.join(fixturesDir, 'todos-app'), appDir, {
recursive: true,
});
await restoreNxIgnoredFiles(appDir);
cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(appDir);
// Windows does not require additional quotation marks for globs
platformSpy = vi.spyOn(os, 'platform').mockReturnValue('win32');
});
afterAll(async () => {
cwdSpy.mockRestore();
platformSpy.mockRestore();
await teardownTestFolder(tmpDir);
});
it('should execute ESLint and create audit results for React application', async () => {
const args = await prepareRunnerArgs('eslint.config.js');
const runnerFn = createRunnerFunction(args);
const res = (await runnerFn({
persist: DEFAULT_PERSIST_CONFIG,
})) as AuditOutputs;
expect(osAgnosticAuditOutputs(res)).toMatchSnapshot();
});
it.skipIf(process.platform === 'win32')(
'should execute runner with custom config using @code-pushup/eslint-config',
async () => {
const eslintTarget = 'code-pushup.eslint.config.mjs';
const runnerFn = createRunnerFunction({
...(await prepareRunnerArgs(eslintTarget)),
});
const json = await runnerFn({ persist: DEFAULT_PERSIST_CONFIG });
// expect warnings from unicorn/filename-case rule from default config
expect(json).toContainEqual(
expect.objectContaining<Partial<AuditOutput>>({
slug: 'unicorn-filename-case',
displayValue: expect.stringMatching(/^\d+ warnings?$/),
details: {
issues: expect.arrayContaining<Issue>([
{
severity: 'warning',
message:
'Filename is not in kebab case. Rename it to `use-todos.js`.',
source: expect.objectContaining<Issue['source']>({
file: path.join(appDir, 'src', 'hooks', 'useTodos.js'),
}),
},
]),
},
}),
);
},
);
}, 20_000);