Skip to content

Commit 8e2507e

Browse files
committed
Make tests CI invariant for testing command
1 parent 3cfd8d5 commit 8e2507e

File tree

1 file changed

+68
-58
lines changed

1 file changed

+68
-58
lines changed

lib/buildtools/src/commands/__tests__/testing.test.ts

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, test, vi } from 'vitest';
1+
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest';
22
import { testMocksDir } from '../../__tests__/fixtures.js';
33
import * as runner from '../../testing/runner.js';
44
import * as configs from '../../testing/utils.js';
@@ -13,75 +13,85 @@ describe('Test regular test command', () => {
1313
const mockedTestConfiguration = vi.spyOn(configs, 'getTestConfiguration');
1414
const runCommand = getCommandRunner(getTestCommand);
1515

16-
test('Providing both the project directory and pattern', async () => {
17-
const mockConfig: configs.GetTestConfigurationResult = {
18-
severity: 'success',
19-
config: {
20-
test: {
21-
name: 'Test0'
16+
describe('Tests that need to be CI process env invariant', () => {
17+
beforeAll(() => {
18+
vi.stubEnv('CI', 'yeet');
19+
});
20+
21+
afterAll(() => {
22+
vi.unstubAllEnvs();
23+
});
24+
25+
test('Providing both the project directory and pattern', async () => {
26+
const mockConfig: configs.GetTestConfigurationResult = {
27+
severity: 'success',
28+
config: {
29+
test: {
30+
name: 'Test0'
31+
}
2232
}
23-
}
24-
};
33+
};
2534

26-
mockedTestConfiguration.mockResolvedValueOnce(mockConfig);
27-
const projectPath = `${testMocksDir}/dir`;
35+
mockedTestConfiguration.mockResolvedValueOnce(mockConfig);
36+
const projectPath = `${testMocksDir}/dir`;
2837

29-
await expect(runCommand('--project', projectPath, `${projectPath}/dir1`)).commandSuccess();
30-
expect(configs.getTestConfiguration).toHaveBeenCalledExactlyOnceWith(projectPath, false);
31-
expect(runner.runVitest).toHaveBeenCalledExactlyOnceWith('test', [`${projectPath}/dir1`], [mockConfig.config], { allowOnly: true });
32-
});
38+
await expect(runCommand('--project', projectPath, `${projectPath}/dir1`)).commandSuccess();
39+
expect(configs.getTestConfiguration).toHaveBeenCalledExactlyOnceWith(projectPath, false);
40+
expect(runner.runVitest).toHaveBeenCalledExactlyOnceWith('test', [`${projectPath}/dir1`], [mockConfig.config], { allowOnly: true });
41+
});
3342

34-
test('Providing both the project directory but no patterns', async () => {
35-
const projectPath = `${testMocksDir}/dir`;
36-
const mockConfig: configs.GetTestConfigurationResult = {
37-
severity: 'success',
38-
config: {
39-
test: {
40-
name: 'Test0'
43+
test('Providing both the project directory but no patterns', async () => {
44+
const projectPath = `${testMocksDir}/dir`;
45+
const mockConfig: configs.GetTestConfigurationResult = {
46+
severity: 'success',
47+
config: {
48+
test: {
49+
name: 'Test0'
50+
}
4151
}
42-
}
43-
};
44-
45-
mockedTestConfiguration.mockResolvedValueOnce(mockConfig);
52+
};
4653

47-
await expect(runCommand('--project', projectPath)).commandSuccess();
48-
expect(configs.getTestConfiguration).toHaveBeenCalledExactlyOnceWith(projectPath, false);
49-
expect(runner.runVitest).toHaveBeenCalledExactlyOnceWith('test', [], [mockConfig.config], { allowOnly: true });
50-
});
54+
mockedTestConfiguration.mockResolvedValueOnce(mockConfig);
5155

52-
test('Expect command to exit with no issues if no tests were found', async () => {
53-
const projectPath = `${testMocksDir}/dir`;
54-
mockedTestConfiguration.mockResolvedValueOnce({
55-
severity: 'success',
56-
config: null
56+
await expect(runCommand('--project', projectPath)).commandSuccess();
57+
expect(configs.getTestConfiguration).toHaveBeenCalledExactlyOnceWith(projectPath, false);
58+
expect(runner.runVitest).toHaveBeenCalledExactlyOnceWith('test', [], [mockConfig.config], { allowOnly: true });
5759
});
5860

59-
await expect(runCommand('--project', projectPath)).commandSuccess();
60-
});
61+
test('Expect command to exit with no issues if no tests were found', async () => {
62+
const projectPath = `${testMocksDir}/dir`;
63+
mockedTestConfiguration.mockResolvedValueOnce({
64+
severity: 'success',
65+
config: null
66+
});
6167

62-
test('Command should error if the command was called from beyond the git root', async () => {
63-
const projectPath = `${testMocksDir}/..`;
64-
await expect(runCommand('--project', projectPath)).commandExit();
65-
});
68+
await expect(runCommand('--project', projectPath)).commandSuccess();
69+
});
70+
71+
test('Command should error if the command was called from beyond the git root', async () => {
72+
const projectPath = `${testMocksDir}/..`;
73+
await expect(runCommand('--project', projectPath)).commandExit();
74+
});
6675

67-
test('--no-allow-only should not allow only :)', async () => {
68-
const mockConfig: configs.GetTestConfigurationResult = {
69-
severity: 'success',
70-
config: {
71-
test: {
72-
name: 'Test0'
76+
test('--no-allow-only should not allow only :)', async () => {
77+
const mockConfig: configs.GetTestConfigurationResult = {
78+
severity: 'success',
79+
config: {
80+
test: {
81+
name: 'Test0'
82+
}
7383
}
74-
}
75-
};
76-
mockedTestConfiguration.mockResolvedValueOnce(mockConfig);
77-
78-
await expect(runCommand('--no-allow-only')).commandSuccess();
79-
expect(runner.runVitest).toHaveBeenCalledExactlyOnceWith(
80-
'test',
81-
[],
82-
[mockConfig.config],
83-
{ allowOnly: false }
84-
);
84+
};
85+
mockedTestConfiguration.mockResolvedValueOnce(mockConfig);
86+
87+
await expect(runCommand('--no-allow-only')).commandSuccess();
88+
expect(runner.runVitest).toHaveBeenCalledExactlyOnceWith(
89+
'test',
90+
[],
91+
[mockConfig.config],
92+
{ allowOnly: false }
93+
);
94+
});
8595
});
8696

8797
test('--no-allow-only should be true when CI', async () => {

0 commit comments

Comments
 (0)