Skip to content

Commit c0af565

Browse files
committed
test: add test case for file ref JSON contents
1 parent 7581c15 commit c0af565

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

packages/cli/tests/__snapshots__/create-tutorial.test.ts.snap

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,58 @@ exports[`create a project 1`] = `
9494
]
9595
`;
9696

97+
exports[`create and build a project > built project file references 1`] = `
98+
"{
99+
"1-basics-1-introduction-1-welcome-files.json": [
100+
"/src/index.js",
101+
"/src/test/bar.js"
102+
],
103+
"1-basics-1-introduction-2-foo-files.json": [
104+
"/bar/styles.css",
105+
"/src/index.html",
106+
"/src/unicorn.js",
107+
"/src/windows_xp.png"
108+
],
109+
"1-basics-1-introduction-3-bar-files.json": [
110+
"/src/index.html"
111+
],
112+
"1-basics-1-introduction-1-welcome-solution.json": [
113+
"/src/index.js"
114+
],
115+
"1-basics-1-introduction-2-foo-solution.json": [
116+
"/src/index.html"
117+
],
118+
"template-default.json": [
119+
"/package-lock.json",
120+
"/package.json",
121+
"/src/index.js"
122+
],
123+
"template-vite-app-2.json": [
124+
"/.gitignore",
125+
"/counter.js",
126+
"/foo.txt",
127+
"/index.html",
128+
"/javascript.svg",
129+
"/main.js",
130+
"/package-lock.json",
131+
"/package.json",
132+
"/public/vite.svg",
133+
"/style.css"
134+
],
135+
"template-vite-app.json": [
136+
"/.gitignore",
137+
"/counter.js",
138+
"/index.html",
139+
"/javascript.svg",
140+
"/main.js",
141+
"/package-lock.json",
142+
"/package.json",
143+
"/public/vite.svg",
144+
"/style.css"
145+
]
146+
}"
147+
`;
148+
97149
exports[`create and build a project 1`] = `
98150
[
99151
"1-basics",

packages/cli/tests/create-tutorial.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { execa } from 'execa';
22
import fs from 'node:fs/promises';
3+
import { readFileSync } from 'node:fs';
34
import { tmpdir } from 'node:os';
45
import path from 'node:path';
56
import { afterAll, beforeAll, expect, test } from 'vitest';
@@ -67,6 +68,20 @@ test('create and build a project', async (context) => {
6768
const distFiles = await fs.readdir(path.join(dest, 'dist'), { recursive: true });
6869

6970
expect(distFiles.map(normaliseSlash).sort()).toMatchSnapshot();
71+
72+
// create snapshot of lesson, solution and template file reference JSONs
73+
const lessonJsons = distFiles.filter((file) => file.endsWith('-files.json'));
74+
const solutionJsons = distFiles.filter((file) => file.endsWith('-solution.json'));
75+
const templateJsons = distFiles.filter((file) => file.startsWith('template-') && file.endsWith('.json'));
76+
77+
const contents = [...lessonJsons, ...solutionJsons, ...templateJsons].reduce((jsons, current) => {
78+
const fileJson = JSON.parse(readFileSync(path.join(dest, 'dist', current), 'utf8'));
79+
const filenames = Object.keys(fileJson);
80+
81+
return { ...jsons, [current]: filenames };
82+
}, {});
83+
84+
expect(JSON.stringify(contents, null, 2)).toMatchSnapshot('built project file references');
7085
});
7186

7287
test('create and eject a project', async (context) => {

0 commit comments

Comments
 (0)