Skip to content

Commit

Permalink
[chore] test debugging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jul 25, 2021
1 parent 68c3906 commit d0f2afd
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ prog
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
const config = await get_config();

const { start } = await import('./core/start/index.js');
const { preview } = await import('./core/preview/index.js');

try {
await start({ port, host, config, https });
await preview({ port, host, config, https });

welcome({ port, host, https, open });
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ const mutable = (dir) =>
* cwd?: string;
* }} opts
*/
export async function start({ port, host, config, https: use_https = false, cwd = process.cwd() }) {
export async function preview({
port,
host,
config,
https: use_https = false,
cwd = process.cwd()
}) {
__fetch_polyfill();

const app_file = resolve(cwd, `${SVELTE_KIT}/output/server/app.js`);
Expand Down
16 changes: 16 additions & 0 deletions packages/kit/test/apps/amp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "test-amp",
"private": true,
"version": "0.0.1",
"scripts": {
"dev": "../../../svelte-kit.js dev",
"build": "../../../svelte-kit.js build",
"preview": "../../../svelte-kit.js preview"
},
"devDependencies": {
"@sveltejs/adapter-node": "workspace:*",
"@sveltejs/kit": "workspace:*",
"svelte": "^3.40.0"
},
"type": "module"
}
2 changes: 1 addition & 1 deletion packages/kit/test/apps/amp/src/routes/host/_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as assert from 'uvu/assert';
export default function (test) {
// this test lives in the AMP app because `basics` has `hostHeader`
// configured, and `options` has `host` configured
test('sets host', '/host', async ({ base, page }) => {
test('sets host amp', '/host', async ({ base, page }) => {
const hostname = new URL(base).host;
assert.equal(await page.textContent('[data-source="load"]'), hostname);
assert.equal(await page.textContent('[data-source="store"]'), hostname);
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/apps/basics/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "test/basics",
"name": "test-basics",
"private": true,
"version": "0.0.1",
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions packages/kit/test/apps/options/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "test-options",
"private": true,
"version": "0.0.1",
"scripts": {
"dev": "../../../svelte-kit.js dev",
"build": "../../../svelte-kit.js build",
"preview": "../../../svelte-kit.js preview"
},
"devDependencies": {
"@sveltejs/adapter-node": "workspace:*",
"@sveltejs/kit": "workspace:*",
"svelte": "^3.40.0"
},
"type": "module"
}
18 changes: 11 additions & 7 deletions packages/kit/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fetch from 'node-fetch';
import { chromium } from 'playwright-chromium';
import { dev } from '../src/core/dev/index.js';
import { build } from '../src/core/build/index.js';
import { start } from '../src/core/start/index.js';
import { preview } from '../src/core/preview/index.js';
import { load_config } from '../src/core/config/index.js';
import { fileURLToPath, pathToFileURL } from 'url';
import { format } from 'util';
Expand All @@ -17,7 +17,7 @@ import { format } from 'util';
async function setup({ port }) {
const base = `http://localhost:${port}`;

const browser = await chromium.launch();
const browser = await chromium.launch({ headless: true });

const contexts = {
js: await browser.newContext({ javaScriptEnabled: true }),
Expand Down Expand Up @@ -165,10 +165,11 @@ function duplicate(test_fn, config, is_build) {
if (!dev) return;
}

if (process.env.FILTER && !name.includes(process.env.FILTER)) return;

if (nojs) {
test_fn(`${name} [no js]`, async (context) => {
name = `${name} [no js]`;
if (process.env.FILTER && !name.includes(process.env.FILTER)) return;

test_fn(name, async (context) => {
let response;

if (start) {
Expand All @@ -188,7 +189,10 @@ function duplicate(test_fn, config, is_build) {
}

if (js && !config.kit.amp) {
test_fn(`${name} [js]`, async (context) => {
name = `${name} [js]`;
if (process.env.FILTER && !name.includes(process.env.FILTER)) return;

test_fn(name, async (context) => {
let response;

if (start) {
Expand Down Expand Up @@ -332,7 +336,7 @@ async function main() {
runtime: '../../../../../src/runtime/server/index.js'
});

context.server = await start({ port, config, cwd, host: undefined, https: false });
context.server = await preview({ port, config, cwd, host: undefined, https: false });
Object.assign(context, await setup({ port }));
} catch (e) {
// the try-catch is necessary pending https://github.com/lukeed/uvu/issues/80
Expand Down

0 comments on commit d0f2afd

Please sign in to comment.