-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathstart.spec.ts
More file actions
106 lines (92 loc) · 2.17 KB
/
Copy pathstart.spec.ts
File metadata and controls
106 lines (92 loc) · 2.17 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
97
98
99
100
101
102
103
104
105
106
import { Command } from 'commander';
import { execa } from 'execa';
import { join } from 'node:path';
import { afterEach, beforeAll, beforeEach, expect, test, vi } from 'vitest';
import { consola } from '../lib/logger';
import { program } from '../program';
import { start } from './start';
vi.mock('node:fs', () => ({
existsSync: vi.fn(() => true),
}));
vi.mock('execa', () => ({
execa: vi.fn(() => Promise.resolve({})),
__esModule: true,
}));
vi.mock('../../src/lib/project-config', () => ({
getProjectConfig: vi.fn(() => ({
get: vi.fn((key) => {
if (key === 'framework') {
return 'catalyst';
}
return undefined;
}),
})),
}));
beforeAll(() => {
consola.wrapAll();
});
beforeEach(() => {
consola.mockTypes(() => vi.fn());
});
afterEach(() => {
vi.clearAllMocks();
});
test('properly configured Command instance', () => {
expect(start).toBeInstanceOf(Command);
expect(start.name()).toBe('start');
expect(start.description()).toBe('Start your Catalyst storefront in optimized production mode.');
expect(start.options).toEqual(
expect.arrayContaining([
expect.objectContaining({
flags: '--framework <framework>',
argChoices: ['catalyst', 'nextjs'],
}),
]),
);
});
test('calls execa with Next.js production optimized server', async () => {
await program.parseAsync([
'node',
'catalyst',
'start',
'--port',
'3001',
'--framework',
'nextjs',
]);
expect(execa).toHaveBeenCalledWith(
join('node_modules', '.bin', 'next'),
['start', '--port', '3001'],
expect.objectContaining({
stdio: 'inherit',
cwd: process.cwd(),
}),
);
});
test('calls execa with OpenNext production optimized server', async () => {
await program.parseAsync([
'node',
'catalyst',
'start',
'--port',
'3001',
'--framework',
'catalyst',
]);
expect(execa).toHaveBeenCalledWith(
'pnpm',
[
'exec',
'opennextjs-cloudflare',
'preview',
'--config',
join('.bigcommerce', 'wrangler.jsonc'),
'--port',
'3001',
],
expect.objectContaining({
stdio: 'inherit',
cwd: process.cwd(),
}),
);
});