Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure isolated testing of create-svelte with local packages #5524

Merged
merged 6 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ yarn.lock
.netlify
.turbo
.vercel
.test-tmp
65 changes: 58 additions & 7 deletions packages/create-svelte/test/check.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,81 @@
import fs from 'fs';
import { execSync } from 'child_process';
import path from 'path';
import { test } from 'uvu';
import { create } from '../index.js';
import { fileURLToPath } from 'url';
// use a directory outside of packages to ensure it isn't added to the pnpm workspace
const test_workspace_dir = fileURLToPath(
new URL('../../../.test-tmp/create-svelte/', import.meta.url)
);
const overrides = {};
['kit', 'adapter-auto', 'adapter-cloudflare', 'adapter-netlify', 'adapter-vercel'].forEach(
(pkg) => {
overrides[`@sveltejs/${pkg}`] = `${path.resolve(
test_workspace_dir,
'..',
'..',
'packages',
pkg
)}`; //'workspace:*';
}
);
test.before(() => {
try {
// prepare test pnpm workspace
fs.rmSync(test_workspace_dir, { recursive: true, force: true });
fs.mkdirSync(test_workspace_dir, { recursive: true });
const workspace = {
name: 'svelte-check-test-fake-pnpm-workspace',
private: true,
version: '0.0.0',
pnpm: { overrides },
devDependencies: overrides
};
fs.writeFileSync(
path.join(test_workspace_dir, 'package.json'),
JSON.stringify(workspace, null, '\t')
);
fs.writeFileSync(path.join(test_workspace_dir, 'pnpm-workspace.yaml'), 'packages:\n - ./*\n');

const dir = '.test-tmp';

test.after(() => {
fs.rmSync(dir, { recursive: true, force: true });
// force creation of pnpm-lock.yaml in test workspace
execSync('pnpm install --no-frozen-lockfile', { dir: test_workspace_dir, stdio: 'inherit' });
} catch (e) {
console.error('failed to setup create-svelte test workspace', e);
throw e;
}
});

for (const template of fs.readdirSync('templates')) {
for (const types of ['checkjs', 'typescript']) {
test(`${template}: ${types}`, () => {
const cwd = `${dir}/${template}-${types}`;
const cwd = path.join(test_workspace_dir, `${template}-${types}`);
fs.rmSync(cwd, { recursive: true, force: true });

create(cwd, {
name: 'test',
name: `create-svelte-test-${template}-${types}`,
template,
types,
prettier: false,
eslint: false,
playwright: false
});
const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'));
Object.entries(overrides).forEach(([key, value]) => {
if (pkg.devDependencies?.[key]) {
pkg.devDependencies[key] = value;
}
if (pkg.dependencies?.[key]) {
pkg.dependencies[key] = value;
}
});
fs.writeFileSync(path.join(cwd, 'package.json'), JSON.stringify(pkg, null, '\t'));

// this pnpm install works in the test workspace, which redirects to our local packages again
execSync('pnpm install --no-frozen-lockfile', { cwd, stdio: 'inherit' });

execSync('pnpm i --no-frozen-lockfile && pnpm check', { cwd, stdio: 'inherit' });
// run check command separately
execSync('pnpm check', { cwd, stdio: 'inherit' });
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ packages:
- 'packages/kit/test/apps/*'
- 'packages/kit/test/prerendering/*'
- 'packages/create-svelte/templates/*'
- 'packages/create-svelte/.test-tmp/*'
- '!.test-tmp/**'