Skip to content
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
2 changes: 1 addition & 1 deletion packages/kit/src/api/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class Watcher extends EventEmitter {

this.server.close();
this.cheapwatch.close();
this.snowpack.shutdown();
return this.snowpack.shutdown();
}
}

Expand Down
1 change: 0 additions & 1 deletion test/apps/amp/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ runner(
const tests = [];

for (const file of modules) {
console.log(file);
const mod = await import(`${cwd}/${file}`);
tests.push(mod.default);
}
Expand Down
3 changes: 2 additions & 1 deletion test/apps/basics/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "test-basics",
"private": true,
"type": "module",
"version": "0.0.2",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"start": "svelte-kit start",
"test": "uvu test"
"test": "node test"
},
"devDependencies": {
"@sveltejs/adapter-node": "workspace:*",
Expand Down
File renamed without changes.
40 changes: 26 additions & 14 deletions test/apps/basics/test/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import path from 'path';
import glob from 'tiny-glob/sync.js';
import * as assert from 'uvu/assert';
import { runner } from '../../../runner'; // TODO make this a package?
import { fileURLToPath } from 'url';
import { runner } from '../../../runner.js'; // TODO make this a package?

runner((test, is_dev) => {
const cwd = path.join(__dirname, '../src/routes');
const modules = glob('**/__tests__.js', { cwd });
for (const module of modules) {
require(`../src/routes/${module}`).default(test, is_dev);
}
runner(
async () => {
const __filename = fileURLToPath(import.meta.url);
const cwd = path.join(__filename, '../../src/routes');
const modules = glob('**/__tests__.js', { cwd });

const tests = [];

for (const file of modules) {
const mod = await import(`${cwd}/${file}`);
tests.push(mod.default);
}

test('static files', async ({ fetch }) => {
let res = await fetch('/static.json');
assert.equal(await res.json(), 'static file');
tests.push(suite => {
suite('static files', async ({ fetch }) => {
let res = await fetch('/static.json');
assert.equal(await res.json(), 'static file');

res = await fetch('/subdirectory/static.json');
assert.equal(await res.json(), 'subdirectory file');
});
});
res = await fetch('/subdirectory/static.json');
assert.equal(await res.json(), 'subdirectory file');
});
});

return tests;
}
);
3 changes: 2 additions & 1 deletion test/apps/options/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "test-options",
"private": true,
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"start": "svelte-kit start",
"test": "uvu"
"test": "node test"
},
"devDependencies": {
"@sveltejs/adapter-node": "workspace:*",
Expand Down
File renamed without changes.
50 changes: 31 additions & 19 deletions test/apps/options/test/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import path from 'path';
import glob from 'tiny-glob/sync.js';
import * as assert from 'uvu/assert';
import { runner } from '../../../runner'; // TODO make this a package?
import { fileURLToPath } from 'url';
import { runner } from '../../../runner.js'; // TODO make this a package?

runner((test, is_dev) => {
const cwd = path.join(__dirname, '../source/pages');
const modules = glob('**/__tests__.js', { cwd });
for (const module of modules) {
require(`../source/pages/${module}`).default(test, is_dev);
}
runner(
async () => {
const __filename = fileURLToPath(import.meta.url);
const cwd = path.join(__filename, '../../source/pages');
const modules = glob('**/__tests__.js', { cwd });

const tests = [];

for (const file of modules) {
const mod = await import(`${cwd}/${file}`);
tests.push(mod.default);
}

test('serves /', async ({ visit, contains, js }) => {
await visit('/');
assert.ok(await contains('I am in the template'), 'Should show custom template contents');
assert.ok(await contains("We're on index.svelte"), 'Should show page contents');
assert.ok(
await contains(
`Hello from the ${js ? 'client' : 'server'} in ${is_dev ? 'dev' : 'prod'} mode!`
),
'Should run JavaScript'
);
});
});
tests.push((suite, is_dev) => {
suite('serves /', async ({ visit, contains, js }) => {
await visit('/');
assert.ok(await contains('I am in the template'), 'Should show custom template contents');
assert.ok(await contains("We're on index.svelte"), 'Should show page contents');
assert.ok(
await contains(
`Hello from the ${js ? 'client' : 'server'} in ${is_dev ? 'dev' : 'prod'} mode!`
),
'Should run JavaScript'
);
});
});

return tests;
}
);
19 changes: 14 additions & 5 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,23 @@ async function setup({ port }) {
pathname: () => page.url().replace(base, ''),
keyboard: page.keyboard,
sleep: (ms) => new Promise((f) => setTimeout(f, ms)),
reset: () => browser && browser.close(),
$: (selector) => page.$(selector)
};
}

globalThis.UVU_DEFER = 1;

export async function runner(prepare_tests, options = {}) {
globalThis.UVU_DEFER = 1;
const uvu = await import('uvu');

async function run(is_dev, { before, after }) {
const suite = uvu.suite(is_dev ? 'dev' : 'build');
const name = is_dev ? 'dev' : 'build';

// manually replicate uvu global state
const count = globalThis.UVU_QUEUE.push([name]);
globalThis.UVU_INDEX = count - 1;

const suite = uvu.suite(name);
const tests = await prepare_tests();

suite.before(before);
Expand Down Expand Up @@ -144,7 +150,7 @@ export async function runner(prepare_tests, options = {}) {
},
async after(context) {
await context.watcher.close();
if (context.browser) await context.browser.close();
await context.reset();
}
});

Expand All @@ -167,7 +173,10 @@ export async function runner(prepare_tests, options = {}) {
},
async after(context) {
context.server.close();
if (context.browser) await context.browser.close();
await context.reset();
}
});

await uvu.exec();
process.exit(process.exitCode || 0);
}