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
3 changes: 3 additions & 0 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
- name: Build
run: pnpm run build

- name: Install Playwright browsers
run: pnpm run playwright:install

- name: Test
run: pnpm run test:all

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ toml-patch.code-workspace
*.cpuprofile
benchmark-*.md


test-results/
playwright-report/
42 changes: 42 additions & 0 deletions browser-tests/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { test, expect } from '@playwright/test';
import { readFileSync } from 'fs';
import { join } from 'path';

const bundle = readFileSync(join(process.cwd(), 'dist/toml-patch.js'), 'utf-8');

// Load the bundle into the page via a blob URL so it runs in a real browser
// module context — no Node.js APIs available.
async function loadTOML(page: import('@playwright/test').Page) {
await page.goto('about:blank');
await page.evaluate(async (src: string) => {
const blob = new Blob([src], { type: 'application/javascript' });
const url = URL.createObjectURL(blob);
(window as any).__TOML__ = await import(url);
URL.revokeObjectURL(url);
}, bundle);
}

test.beforeEach(async ({ page }) => {
await loadTOML(page);
});

test('parse should work in real browser', async ({ page }) => {
const result = await page.evaluate(() =>
(window as any).__TOML__.parse('key = "hello"')
);
expect(result).toEqual({ key: 'hello' });
});

test('stringify should work in real browser', async ({ page }) => {
const result = await page.evaluate(() =>
(window as any).__TOML__.stringify({ key: 'hello' })
);
expect(result).toBe('key = "hello"\n');
});

test('patch should work in real browser', async ({ page }) => {
const result = await page.evaluate(() =>
(window as any).__TOML__.patch('key = "hello"\n', { key: 'world' })
);
expect(result).toBe('key = "world"\n');
});
1 change: 1 addition & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"testEnvironment": "node",
"preset": "ts-jest",
"testRegex": "/__tests__/(?!__js__).*\\.[jt]sx?$",
"testPathIgnorePatterns": ["<rootDir>/worktrees/"],
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
Expand Down
1 change: 1 addition & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export default {
testEnvironment: 'node',
testRegex: '/__tests__/.*\\.mjs$',
testPathIgnorePatterns: ['<rootDir>/worktrees/'],
transform: {},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"dev": "pnpm run typecheck && pnpm run build && npm-run-all2 --parallel test:all specs",
"test": "jest --config jest.config.json",
"test:js": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.mjs",
"test:all": "pnpm run test && pnpm run test:js",
"test:playwright": "playwright test",
"playwright:install": "playwright install --with-deps chromium",
"test:all": "pnpm run test && pnpm run test:js && pnpm run test:playwright",
"typecheck": "tsc",
"specs": "jest --config specs.config.cjs",
"benchmark": "npm-run-all2 bench:*",
Expand All @@ -53,6 +55,7 @@
},
"devDependencies": {
"@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@1.0.7",
"@playwright/test": "^1.59.1",
"@rollup/plugin-terser": "^1.0.0",
"@rollup/plugin-typescript": "^12.1.2",
"@types/dedent": "^0.7.2",
Expand Down
8 changes: 8 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from '@playwright/test';

export default defineConfig({
testDir: './browser-tests',
projects: [
{ name: 'chromium', use: { browserName: 'chromium' } },
],
});
38 changes: 38 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"noEmit": true,
"skipLibCheck": true
},
"include": ["src/**/*"],
"include": ["*.ts", "src/**/*"],
"exclude": ["node_modules"]
}