Skip to content
Open
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
8 changes: 6 additions & 2 deletions playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import { test as base, expect } from '@playwright/test';
import type { TestInfo } from '@playwright/test';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { ACTION_FAIL, ACTION_SKIP, AgentClient, KeployError } from './agent';
import type { Outcome, TestRef } from './agent';
Expand Down Expand Up @@ -172,9 +173,12 @@ const SOURCE_MAX = 1024;
export function sourceOf(stack: string, dir = projectDir): string {
const own = path.dirname(__filename);
for (const line of stack.split('\n').slice(1)) {
const m = /\(?((?:file:\/\/)?[^\s()]+):(\d+):\d+\)?\s*$/.exec(line.trim());
const m = /\(?((?:file:\/\/)?[^()]+):(\d+):\d+\)?\s*$/.exec(line.trim());
if (!m) continue;
let file = m[1].startsWith('file://') ? new URL(m[1]).pathname : m[1];
const location = m[1].replace(/^at\s+(?:async\s+)?/, '');
let file: string;
try { file = location.startsWith('file://') ? fileURLToPath(location) : location; }
catch { continue; }
if (!path.isAbsolute(file) || path.dirname(file) === own || file.startsWith('node:')) continue;
file = toSlash(path.relative(dir || process.cwd(), file));
const s = `${file}:${m[2]}`;
Expand Down
5 changes: 5 additions & 0 deletions playwright/test/fixtures/given caller with spaces.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test, given } from '../../dist';

test('caller with spaces', async () => {
await given('customer', 'customer-1');
});
13 changes: 13 additions & 0 deletions playwright/test/rows.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ test('a worker claims the run, each test begins before its beforeEach and ends w
} finally { await a.close(); }
});

test('given sends its caller path as it appears on disk when the filename has spaces', async () => {
const j = journal();
const a = await fakeAgent(j);
try {
const { tests, out } = await playwright(['given caller with spaces.spec.ts'], keployEnv(a.url));
assert.equal(tests['caller with spaces'].status, 'passed', out);
const call = calls(j).find((c) => c.path === '/agent/scope/given');
assert.deepEqual(call?.body, {
name: 'customer', value: 'customer-1', source: 'test/fixtures/given caller with spaces.spec.ts:4',
}, out);
} finally { await a.close(); }
});

test('keploy skips a set-aside test with its reason, fails a judged-red one, and a refused begin fails the test', async () => {
const j = journal();
const a = await fakeAgent(j, (c) => {
Expand Down
7 changes: 7 additions & 0 deletions playwright/test/unit.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fs from 'node:fs';
import http from 'node:http';
import os from 'node:os';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { AgentClient, KeployError } from '../dist/agent.js';
import { decide } from '../dist/join.js';
import { Inflight } from '../dist/settle.js';
Expand Down Expand Up @@ -279,6 +280,12 @@ test('sourceOf: the first frame outside the package, relative to the project', (
assert.equal(sourceOf(stack, '/proj'), 'tests/a.spec.ts:12');
assert.equal(sourceOf(['Error', ' at Object.<anonymous> (/proj/t/b.spec.ts:3:1)'].join('\n'), '/proj'), 't/b.spec.ts:3');
assert.equal(sourceOf(['Error', ' at x (file:///proj/t/c.spec.mjs:4:2)'].join('\n'), '/proj'), 't/c.spec.mjs:4');
const encoded = pathToFileURL('/proj/t/a b.spec.mjs').href;
assert.equal(sourceOf(`Error\n at x (${encoded}:5:2)`, '/proj'), 't/a b.spec.mjs:5');
assert.equal(sourceOf('Error\n at /proj/t/a b.spec.ts:5:2', '/proj'), 't/a b.spec.ts:5');
assert.equal(sourceOf('Error\n at async /proj/t/a b.spec.ts:5:2', '/proj'), 't/a b.spec.ts:5');
assert.equal(sourceOf('Error\n at async /proj/t/a.spec.ts:5:2', '/proj'), 't/a.spec.ts:5');
assert.equal(sourceOf('Error\n at eval (file:///proj/a%2Fb.spec.ts:1:1)\n at /proj/a.spec.ts:2:1', '/proj'), 'a.spec.ts:2');
assert.equal(sourceOf('Error\n at <anonymous>', '/proj'), '');
});

Expand Down