Skip to content

Commit 19929b4

Browse files
committed
feat(vitest): add setup files configuration to Vitest base config
1 parent c889844 commit 19929b4

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// FAIL LOUDLY on unhandled promise rejections / errors
2+
process.on('unhandledRejection', (reason) => {
3+
console.log(`******** FAILED TO HANDLE PROMISE REJECTION ********`);
4+
throw reason;
5+
});

packages/config-vite-base/src/vitest.base.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function createVitestConfig(
2525
},
2626
},
2727
root,
28+
setupFiles: ['./setup.ts'],
2829
testTimeout: platform() === 'win32' ? 10000 : 5000,
2930
},
3031
});

packages/nx-plugin/src/utils.spec.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ describe('utils', () => {
129129

130130
describe('generateClientCode', () => {
131131
it('should execute command successfully', async () => {
132-
await generateClientCode({
133-
clientType: '@hey-api/client-fetch',
134-
outputPath: './src/generated',
135-
plugins: [],
136-
specFile: './api/spec.yaml',
137-
});
132+
await expect(
133+
generateClientCode({
134+
clientType: '@hey-api/client-fetch',
135+
outputPath: './src/generated',
136+
plugins: [],
137+
specFile: './api/spec.yaml',
138+
}),
139+
).resolves.not.toThrow();
138140

139141
expect(createClient).toHaveBeenCalledWith({
140142
input: './api/spec.yaml',
@@ -148,22 +150,14 @@ describe('utils', () => {
148150
throw new Error('Command failed');
149151
});
150152

151-
try {
152-
await generateClientCode({
153+
await expect(
154+
generateClientCode({
153155
clientType: '@hey-api/client-fetch',
154156
outputPath: './src/generated',
155157
plugins: [],
156158
specFile: './api/spec.yaml',
157-
});
158-
// If we get here, fail the test
159-
expect.fail('Expected function to throw');
160-
} catch (error) {
161-
if (error instanceof Error) {
162-
expect(error.message).toContain('Command failed');
163-
} else {
164-
expect.fail('Expected error to be an instance of Error');
165-
}
166-
}
159+
}),
160+
).rejects.toThrow('Command failed');
167161
});
168162
});
169163

0 commit comments

Comments
 (0)