-
Notifications
You must be signed in to change notification settings - Fork 287
/
Copy pathintegration.test.ts
69 lines (61 loc) · 3.67 KB
/
integration.test.ts
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
import path from 'node:path';
import fs from 'node:fs/promises';
import {createRequire} from 'node:module';
import {execa} from 'execa';
import {temporaryDirectoryTask} from 'tempy';
import {describe, it, expect} from 'vitest';
describe('create-hydrogen', () => {
it('creates a quickstart project using the compiled files', async () => {
const packageJson = createRequire(import.meta.url)('./package.json');
const bin = path.resolve(packageJson.bin);
expect(bin).toMatch(/\bdist\/.*\.m?js$/);
await expect(
fs.stat(bin).catch(() => false),
`It looks like there are no compiled files for create-hydrogen in ${bin}.` +
`Please build the project before running the tests`,
).resolves.toBeTruthy();
await temporaryDirectoryTask(async (tmpDir) => {
const processPromise = execa('node', [
bin,
'--quickstart',
'--no-install-deps',
'--no-shortcut',
'--path',
tmpDir,
]);
await expect(processPromise, 'create-app process').resolves.toBeTruthy();
await expect(
fs.stat(path.resolve(tmpDir, 'package.json')).catch(() => false),
).resolves.toBeTruthy();
// Replace the temporary directory with a placeholder to avoid snapshot noise.
// The directory can wrap to a new line, so we can't use a simple string replace.
const output = (await processPromise).stdout
.replace(/^.*╭/ims, '╭')
.replace(/Run `.*$/s, 'Run `<redacted-command-for-test>`');
expect(output).toMatchInlineSnapshot(`
"╭─ success ────────────────────────────────────────────────────────────────────╮
│ │
│ Storefront setup complete! │
│ │
│ Shopify: Mock.shop │
│ Language: JavaScript │
│ Routes: │
│ • Home (/ & /:catchAll) │
│ • Page (/pages/:handle) │
│ • Cart (/cart/* & /discount/*) │
│ • Products (/products/:handle) │
│ • Collections (/collections/*) │
│ • Policies (/policies & /policies/:handle) │
│ • Blogs (/blogs/*) │
│ • Account (/account/*) │
│ • Search (/search) │
│ • Robots (/robots.txt) │
│ • Sitemap (/sitemap.xml & /sitemap/:type/:page.xml) │
│ │
│ Next steps │
│ │
│ • Run \`<redacted-command-for-test>\`"
`);
});
});
});