Skip to content

Commit da0e18e

Browse files
author
John Doe
committed
refactor: apply renaming to test-app
1 parent 5879368 commit da0e18e

File tree

5 files changed

+49
-21
lines changed

5 files changed

+49
-21
lines changed

packages/plugin-eslint/mocks/fixtures/todos-app/package.json renamed to packages/plugin-eslint/mocks/fixtures/todos-app/_package.json

File renamed without changes.

packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import process from 'node:process';
66
import { fileURLToPath } from 'node:url';
77
import type { MockInstance } from 'vitest';
88
import type { Audit } from '@code-pushup/models';
9-
import { restoreNxIgnoredFiles } from '@code-pushup/test-utils';
9+
import {
10+
restoreNxIgnoredFiles,
11+
teardownTestFolder,
12+
} from '@code-pushup/test-utils';
1013
import { eslintPlugin } from './eslint-plugin.js';
1114

1215
describe('eslintPlugin', () => {
@@ -24,18 +27,25 @@ describe('eslintPlugin', () => {
2427
{ recursive: true },
2528
);
2629
await restoreNxIgnoredFiles(path.join(tmpDir, 'nx-monorepo'));
30+
await cp(
31+
path.join(fixturesDir, 'todos-app'),
32+
path.join(tmpDir, 'todos-app'),
33+
{ recursive: true },
34+
);
35+
await restoreNxIgnoredFiles(path.join(tmpDir, 'todos-app'));
2736
cwdSpy = vi.spyOn(process, 'cwd');
2837
// Linux produces extra quotation marks for globs
2938
platformSpy = vi.spyOn(os, 'platform').mockReturnValue('linux');
3039
});
3140

32-
afterAll(() => {
41+
afterAll(async () => {
3342
cwdSpy.mockRestore();
3443
platformSpy.mockRestore();
44+
await teardownTestFolder(tmpDir);
3545
});
3646

3747
it('should initialize ESLint plugin for React application', async () => {
38-
cwdSpy.mockReturnValue(path.join(fixturesDir, 'todos-app'));
48+
cwdSpy.mockReturnValue(path.join(tmpDir, 'todos-app'));
3949

4050
const plugin = await eslintPlugin({
4151
eslintrc: 'eslint.config.js',
@@ -148,7 +158,7 @@ describe('eslintPlugin', () => {
148158
});
149159

150160
it('should initialize with artifact options', async () => {
151-
cwdSpy.mockReturnValue(path.join(fixturesDir, 'todos-app'));
161+
cwdSpy.mockReturnValue(path.join(tmpDir, 'todos-app'));
152162
const plugin = await eslintPlugin(
153163
{
154164
eslintrc: 'eslint.config.js',

packages/plugin-eslint/src/lib/meta/rules.int.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import path from 'node:path';
33
import process from 'node:process';
44
import { fileURLToPath } from 'node:url';
55
import type { MockInstance } from 'vitest';
6-
import { restoreNxIgnoredFiles } from '@code-pushup/test-utils';
6+
import {
7+
restoreNxIgnoredFiles,
8+
teardownTestFolder,
9+
} from '@code-pushup/test-utils';
710
import type { ESLintTarget } from '../config.js';
811
import type { RuleData } from './parse.js';
912
import { listRules } from './rules.js';
@@ -25,18 +28,23 @@ describe('listRules', () => {
2528
cwdSpy = vi.spyOn(process, 'cwd');
2629
});
2730

28-
afterAll(() => {
31+
afterAll(async () => {
2932
cwdSpy.mockRestore();
33+
await teardownTestFolder(tmpDir);
3034
});
3135

3236
describe('React app', () => {
33-
const appRootDir = path.join(fixturesDir, 'todos-app');
37+
const appRootDir = path.join(tmpDir, 'todos-app');
3438
const eslintrc = path.join(appRootDir, 'eslint.config.js');
3539

3640
const patterns = ['src/**/*.js', 'src/**/*.jsx'];
3741
const targets: ESLintTarget[] = [{ eslintrc, patterns }];
3842

39-
beforeAll(() => {
43+
beforeAll(async () => {
44+
await cp(path.join(fixturesDir, 'todos-app'), appRootDir, {
45+
recursive: true,
46+
});
47+
await restoreNxIgnoredFiles(appRootDir);
4048
cwdSpy.mockReturnValue(appRootDir);
4149
});
4250

packages/plugin-eslint/src/lib/nx.int.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import path from 'node:path';
33
import process from 'node:process';
44
import { fileURLToPath } from 'node:url';
55
import type { MockInstance } from 'vitest';
6-
import { restoreNxIgnoredFiles } from '@code-pushup/test-utils';
6+
import {
7+
restoreNxIgnoredFiles,
8+
teardownTestFolder,
9+
} from '@code-pushup/test-utils';
710
import { executeProcess } from '@code-pushup/utils';
811
import type { ESLintTarget } from './config.js';
912
import { eslintConfigFromNxProject } from './nx/find-project-without-deps.js';
@@ -36,8 +39,9 @@ describe.skipIf(process.platform === 'win32')('Nx helpers', () => {
3639
});
3740
});
3841

39-
afterAll(() => {
42+
afterAll(async () => {
4043
cwdSpy.mockRestore();
44+
await teardownTestFolder(tmpDir);
4145
});
4246

4347
describe('create config from all Nx projects', () => {

packages/plugin-eslint/src/lib/runner.int.test.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cp } from 'node:fs/promises';
12
import os from 'node:os';
23
import path from 'node:path';
34
import process from 'node:process';
@@ -10,7 +11,11 @@ import {
1011
DEFAULT_PERSIST_CONFIG,
1112
type Issue,
1213
} from '@code-pushup/models';
13-
import { osAgnosticAuditOutputs } from '@code-pushup/test-utils';
14+
import {
15+
osAgnosticAuditOutputs,
16+
restoreNxIgnoredFiles,
17+
teardownTestFolder,
18+
} from '@code-pushup/test-utils';
1419
import type { ESLintTarget } from './config.js';
1520
import { listAuditsAndGroups } from './meta/index.js';
1621
import { createRunnerFunction } from './runner/index.js';
@@ -28,24 +33,25 @@ describe('executeRunner', () => {
2833
return { audits, targets };
2934
};
3035

31-
const appDir = path.join(
32-
fileURLToPath(path.dirname(import.meta.url)),
33-
'..',
34-
'..',
35-
'mocks',
36-
'fixtures',
37-
'todos-app',
38-
);
36+
const thisDir = fileURLToPath(path.dirname(import.meta.url));
37+
const fixturesDir = path.join(thisDir, '..', '..', 'mocks', 'fixtures');
38+
const tmpDir = path.join(process.cwd(), 'tmp', 'int', 'plugin-eslint');
39+
const appDir = path.join(tmpDir, 'todos-app');
3940

40-
beforeAll(() => {
41+
beforeAll(async () => {
42+
await cp(path.join(fixturesDir, 'todos-app'), appDir, {
43+
recursive: true,
44+
});
45+
await restoreNxIgnoredFiles(appDir);
4146
cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(appDir);
4247
// Windows does not require additional quotation marks for globs
4348
platformSpy = vi.spyOn(os, 'platform').mockReturnValue('win32');
4449
});
4550

46-
afterAll(() => {
51+
afterAll(async () => {
4752
cwdSpy.mockRestore();
4853
platformSpy.mockRestore();
54+
await teardownTestFolder(tmpDir);
4955
});
5056

5157
it('should execute ESLint and create audit results for React application', async () => {

0 commit comments

Comments
 (0)