Skip to content

Commit

Permalink
test: create subfolders under tmp for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlacenka committed Mar 7, 2024
1 parent 7dd2934 commit dab5822
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
6 changes: 3 additions & 3 deletions e2e/cli-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('CLI collect', () => {
expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile('tmp/react-todos-app/report.json');
const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('CLI collect', () => {
expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile('tmp/react-todos-app/report.json');
const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
Expand All @@ -105,7 +105,7 @@ describe('CLI collect', () => {
expect(code).toBe(0);
expect(stderr).toBe('');

const md = await readTextFile('tmp/react-todos-app/report.md');
const md = await readTextFile('tmp/e2e/react-todos-app/report.md');

expect(md).toContain('# Code PushUp Report');
expect(md).toContain(exampleCategoryTitle);
Expand Down
2 changes: 1 addition & 1 deletion examples/react-todos-app/code-pushup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const eslintAuditRef = (slug, weight) => ({

export default {
persist: {
outputDir: '../../tmp/react-todos-app',
outputDir: '../../tmp/e2e/react-todos-app',
},
plugins: [
await coveragePlugin({
Expand Down
10 changes: 4 additions & 6 deletions global-setup.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { execSync } from 'child_process';
import {
setup as globalSetup,
teardown as globalTeardown,
} from './global-setup';
import { setupTestFolder } from './testing/test-setup/src';
import { setup as globalSetup } from './global-setup';
import { setupTestFolder, teardownTestFolder } from './testing/test-setup/src';
import startLocalRegistry from './tools/scripts/start-local-registry';
import stopLocalRegistry from './tools/scripts/stop-local-registry';

Expand All @@ -21,5 +18,6 @@ export async function teardown() {
execSync('npm uninstall @code-pushup/cli');
execSync('npm uninstall @code-pushup/eslint-plugin');
execSync('npm uninstall @code-pushup/coverage-plugin');
await globalTeardown();
await teardownTestFolder('tmp/e2e');
await teardownTestFolder('tmp/local-registry');
}
6 changes: 0 additions & 6 deletions global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { teardownTestFolder } from './testing/test-setup/src';

export async function setup() {
process.env.TZ = 'UTC';
}

export async function teardown() {
await teardownTestFolder('tmp');
}
8 changes: 3 additions & 5 deletions packages/utils/src/lib/git.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import {
} from './git';
import { toUnixPath } from './transform';

// we need a separate folder that is not cleaned in `global-setup.ts`, otherwise the tests can't execute in parallel
const gitTestFolder = 'git-test';
describe('git utils in a git repo', () => {
const baseDir = join(process.cwd(), gitTestFolder);
const baseDir = join(process.cwd(), 'tmp', 'git-tests');
let emptyGit: SimpleGit;

beforeAll(async () => {
Expand Down Expand Up @@ -75,12 +73,12 @@ describe('git utils in a git repo', () => {
it('should convert relative Windows path to relative Git path', async () => {
await expect(
toGitPath('Backend\\API\\Startup.cs', emptyGit),
).resolves.toBe('../Backend/API/Startup.cs');
).resolves.toBe('../../Backend/API/Startup.cs');
});

it('should keep relative Unix path as is (already a Git path)', async () => {
await expect(toGitPath('Backend/API/Startup.cs', emptyGit)).resolves.toBe(
'../Backend/API/Startup.cs',
'../../Backend/API/Startup.cs',
);
});

Expand Down

0 comments on commit dab5822

Please sign in to comment.