Skip to content

Commit 6004a22

Browse files
jycouetmanuel3108
andauthored
add create-with-all-addons snapshot (#831)
Co-authored-by: Manuel Serret <[email protected]>
1 parent 1eb3d34 commit 6004a22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1089
-28
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages/cli/tests/snapshots/*

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default [
3131
'**/.test-output/*',
3232
'**/dist/*',
3333
'packages/**/tests/**/{output,input}.ts',
34+
'packages/cli/tests/snapshots/*',
3435
'rolldown.config.js',
3536
'community-addon-template/tests/*'
3637
]

packages/cli/tests/cli.ts

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,75 @@ describe('cli', () => {
3434
'mdsvex',
3535
'paraglide=languageTags:en,es+demo:yes',
3636
'mcp=ide:claude-code,cursor,gemini,opencode,vscode,other+setup:local'
37+
// 'storybook' // No storybook addon during tests!
3738
]
3839
}
3940
];
4041

41-
it.for(testCases)('should create a new project with name $projectName', async (testCase) => {
42-
const { projectName, args } = testCase;
43-
const svBinPath = path.resolve(monoRepoPath, 'packages', 'cli', 'dist', 'bin.js');
44-
const testOutputPath = path.resolve(monoRepoPath, '.test-output', 'cli', projectName);
42+
it.for(testCases)(
43+
'should create a new project with name $projectName',
44+
{ timeout: 10_000 },
45+
async (testCase) => {
46+
const { projectName, args } = testCase;
47+
const svBinPath = path.resolve(monoRepoPath, 'packages', 'cli', 'dist', 'bin.js');
48+
const testOutputPath = path.resolve(monoRepoPath, '.test-output', 'cli', projectName);
4549

46-
const result = await exec(
47-
'node',
48-
[
49-
svBinPath,
50-
'create',
51-
testOutputPath,
52-
'--template',
53-
'minimal',
54-
'--types',
55-
'ts',
56-
'--no-install',
57-
...args
58-
],
59-
{ nodeOptions: { stdio: 'ignore' } }
60-
);
50+
const result = await exec(
51+
'node',
52+
[
53+
svBinPath,
54+
'create',
55+
testOutputPath,
56+
'--template',
57+
'minimal',
58+
'--types',
59+
'ts',
60+
'--no-install',
61+
...args
62+
],
63+
{ nodeOptions: { stdio: 'pipe' } }
64+
);
6165

62-
// cli finished well
63-
expect(result.exitCode).toBe(0);
66+
// cli finished well
67+
expect(result.exitCode).toBe(0);
6468

65-
// test output path exists
66-
expect(fs.existsSync(testOutputPath)).toBe(true);
69+
// test output path exists
70+
expect(fs.existsSync(testOutputPath)).toBe(true);
6771

68-
// package.json has a name
69-
const packageJsonPath = path.resolve(testOutputPath, 'package.json');
70-
const packageJson = parseJson(fs.readFileSync(packageJsonPath, 'utf-8'));
71-
expect(packageJson.name).toBe(projectName);
72-
});
72+
// package.json has a name
73+
const packageJsonPath = path.resolve(testOutputPath, 'package.json');
74+
const packageJson = parseJson(fs.readFileSync(packageJsonPath, 'utf-8'));
75+
expect(packageJson.name).toBe(projectName);
76+
77+
const snapPath = path.resolve(
78+
monoRepoPath,
79+
'packages',
80+
'cli',
81+
'tests',
82+
'snapshots',
83+
projectName
84+
);
85+
const relativeFiles = fs.readdirSync(testOutputPath, { recursive: true }) as string[];
86+
for (const relativeFile of relativeFiles) {
87+
if (!fs.statSync(path.resolve(testOutputPath, relativeFile)).isFile()) continue;
88+
if (['.svg', '.env'].some((ext) => relativeFile.endsWith(ext))) continue;
89+
90+
let generated = fs.readFileSync(path.resolve(testOutputPath, relativeFile), 'utf-8');
91+
if (relativeFile === 'package.json') {
92+
const generatedPackageJson = parseJson(generated);
93+
// remove @types/node from generated package.json as we test on different node versions
94+
delete generatedPackageJson.devDependencies['@types/node'];
95+
generated = JSON.stringify(generatedPackageJson, null, 3).replaceAll(' ', '\t');
96+
}
97+
98+
generated = generated.replaceAll('\r\n', '\n'); // make it work on Windows too
99+
if (!generated.endsWith('\n')) generated += '\n'; // ensure trailing newline
100+
101+
await expect(generated).toMatchFileSnapshot(
102+
path.resolve(snapPath, relativeFile),
103+
`file "${relativeFile}" does not match snapshot`
104+
);
105+
}
106+
}
107+
);
73108
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
node_modules
2+
3+
# Output
4+
.output
5+
.vercel
6+
.netlify
7+
.wrangler
8+
/.svelte-kit
9+
/build
10+
11+
# OS
12+
.DS_Store
13+
Thumbs.db
14+
15+
# Env
16+
.env
17+
.env.*
18+
!.env.example
19+
!.env.test
20+
21+
# Vite
22+
vite.config.js.timestamp-*
23+
vite.config.ts.timestamp-*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# sv
2+
3+
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
4+
5+
## Creating a project
6+
7+
If you're seeing this, you've probably already done this step. Congrats!
8+
9+
```sh
10+
# create a new project in the current directory
11+
npx sv create
12+
13+
# create a new project in my-app
14+
npx sv create my-app
15+
```
16+
17+
## Developing
18+
19+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
20+
21+
```sh
22+
npm run dev
23+
24+
# or start the server and open the app in a new browser tab
25+
npm run dev -- --open
26+
```
27+
28+
## Building
29+
30+
To create a production version of your app:
31+
32+
```sh
33+
npm run build
34+
```
35+
36+
You can preview the production build with `npm run preview`.
37+
38+
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "create-only",
3+
"private": true,
4+
"version": "0.0.1",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite dev",
8+
"build": "vite build",
9+
"preview": "vite preview",
10+
"prepare": "svelte-kit sync || echo ''",
11+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
12+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
13+
},
14+
"devDependencies": {
15+
"@sveltejs/adapter-auto": "^7.0.0",
16+
"@sveltejs/kit": "^2.48.5",
17+
"@sveltejs/vite-plugin-svelte": "^6.2.1",
18+
"svelte": "^5.43.8",
19+
"svelte-check": "^4.3.4",
20+
"typescript": "^5.9.3",
21+
"vite": "^7.2.2"
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// See https://svelte.dev/docs/kit/types#app.d.ts
2+
// for information about these interfaces
3+
declare global {
4+
namespace App {
5+
// interface Error {}
6+
// interface Locals {}
7+
// interface PageData {}
8+
// interface PageState {}
9+
// interface Platform {}
10+
}
11+
}
12+
13+
export {};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
%sveltekit.head%
7+
</head>
8+
<body data-sveltekit-preload-data="hover">
9+
<div style="display: contents">%sveltekit.body%</div>
10+
</body>
11+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// place files you want to import through the `$lib` alias in this folder.

0 commit comments

Comments
 (0)