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
8 changes: 4 additions & 4 deletions packages/adapter-cloudflare/test/apps/workers/test/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

test('worker', async ({ page }) => {
await page.goto('/');
await expect(page.locator('h1')).toContainText('Sum: 3');
Expand All @@ -16,7 +13,10 @@ test('ctx', async ({ request }) => {
});

test('read from $app/server works', async ({ request }) => {
const content = fs.readFileSync(path.resolve(__dirname, '../src/routes/read/file.txt'), 'utf-8');
const content = fs.readFileSync(
path.resolve(import.meta.dirname, '../src/routes/read/file.txt'),
'utf-8'
);
const response = await request.get('/read');
expect(await response.text()).toBe(content);
});
15 changes: 9 additions & 6 deletions packages/adapter-netlify/test/apps/basic/test/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

test('page renders', async ({ request }) => {
const response = await request.get('/');
expect(response.status()).toBe(200);
Expand All @@ -18,17 +15,23 @@ test('dynamic route works', async ({ request }) => {
});

test('read from $app/server works', async ({ request }) => {
const content = fs.readFileSync(path.resolve(__dirname, '../src/routes/read/file.txt'), 'utf-8');
const content = fs.readFileSync(
path.resolve(import.meta.dirname, '../src/routes/read/file.txt'),
'utf-8'
);
const response = await request.get('/read');
expect(await response.text()).toBe(content);
});

test('_redirects are copied to publish directory', () => {
const redirects = fs.readFileSync(path.resolve(__dirname, '../build/_redirects'), 'utf-8');
const redirects = fs.readFileSync(
path.resolve(import.meta.dirname, '../build/_redirects'),
'utf-8'
);
expect(redirects).toContain('/redirect-me /greeting/redirected 301');
});

test('_headers are copied to publish directory', () => {
const headers = fs.readFileSync(path.resolve(__dirname, '../build/_headers'), 'utf-8');
const headers = fs.readFileSync(path.resolve(import.meta.dirname, '../build/_headers'), 'utf-8');
expect(headers).toContain('X-Custom-Header: test-value');
});
10 changes: 5 additions & 5 deletions packages/adapter-netlify/test/apps/edge/test/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

test('page renders', async ({ request }) => {
const response = await request.get('/');
expect(response.status()).toBe(200);
Expand All @@ -18,12 +15,15 @@ test('dynamic route works', async ({ request }) => {
});

test('read from $app/server works', async ({ request }) => {
const content = fs.readFileSync(path.resolve(__dirname, '../src/routes/read/file.txt'), 'utf-8');
const content = fs.readFileSync(
path.resolve(import.meta.dirname, '../src/routes/read/file.txt'),
'utf-8'
);
const response = await request.get('/read');
expect(await response.text()).toBe(content);
});

test('_headers are copied to publish directory', () => {
const headers = fs.readFileSync(path.resolve(__dirname, '../build/_headers'), 'utf-8');
const headers = fs.readFileSync(path.resolve(import.meta.dirname, '../build/_headers'), 'utf-8');
expect(headers).toContain('X-Custom-Header: test-value');
});
2 changes: 1 addition & 1 deletion packages/enhanced-img/test/markup-plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';
import { expect, it } from 'vitest';
import { image_plugin, parse_object } from '../src/vite-plugin.js';

const resolve = /** @param {string} file */ (file) => path.resolve(__dirname, file);
const resolve = /** @param {string} file */ (file) => path.resolve(import.meta.dirname, file);

it('Image preprocess snapshot test', async () => {
const filename = 'Input.svelte';
Expand Down
13 changes: 5 additions & 8 deletions packages/kit/src/core/adapt/builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import { create_builder } from './builder.js';
import { posixify } from '../../utils/filesystem.js';
import { list_files } from '../utils.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = join(__filename, '..');

test('copy files', () => {
const cwd = join(__dirname, 'fixtures/basic');
const cwd = join(import.meta.dirname, 'fixtures/basic');
const outDir = join(cwd, '.svelte-kit');

/** @type {import('@sveltejs/kit').Config} */
Expand All @@ -19,7 +16,7 @@ test('copy files', () => {
kit: {
appDir: '_app',
files: {
assets: join(__dirname, 'fixtures/basic/static')
assets: join(import.meta.dirname, 'fixtures/basic/static')
},
outDir
}
Expand All @@ -42,7 +39,7 @@ test('copy files', () => {
log: {}
});

const dest = join(__dirname, 'output');
const dest = join(import.meta.dirname, 'output');

rmSync(dest, { recursive: true, force: true });

Expand Down Expand Up @@ -74,8 +71,8 @@ test('compress files', async () => {
});

test('instrument generates facade with posix paths', () => {
const fixtureDir = join(__dirname, 'fixtures/instrument');
const dest = join(__dirname, 'output');
const fixtureDir = join(import.meta.dirname, 'fixtures/instrument');
const dest = join(import.meta.dirname, 'output');

rmSync(dest, { recursive: true, force: true });
mkdirSync(join(dest, 'server'), { recursive: true });
Expand Down
14 changes: 5 additions & 9 deletions packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { assert, expect, test } from 'vitest';
import { validate_config, load_config } from './index.js';
import process from 'node:process';

const __filename = fileURLToPath(import.meta.url);
const __dirname = join(__filename, '..');

/**
* mutates and remove keys from an object when check callback returns true
* @param {Record<string, any>} o any object
Expand Down Expand Up @@ -362,7 +358,7 @@ validate_paths(
);

test('load default config (esm)', async () => {
const cwd = join(__dirname, 'fixtures/default');
const cwd = join(import.meta.dirname, 'fixtures/default');

const config = await load_config({ cwd });
remove_keys(config, ([, v]) => typeof v === 'function');
Expand All @@ -374,7 +370,7 @@ test('load default config (esm)', async () => {
});

test('load default config (esm) with .ts extensions', async () => {
const cwd = join(__dirname, 'fixtures/typescript');
const cwd = join(import.meta.dirname, 'fixtures/typescript');

const config = await load_config({ cwd });
remove_keys(config, ([, v]) => typeof v === 'function');
Expand All @@ -386,7 +382,7 @@ test('load default config (esm) with .ts extensions', async () => {
});

test('load .js config when both .js and .ts configs are present', async () => {
const cwd = join(__dirname, 'fixtures/multiple');
const cwd = join(import.meta.dirname, 'fixtures/multiple');

const config = await load_config({ cwd });
remove_keys(config, ([, v]) => typeof v === 'function');
Expand All @@ -401,7 +397,7 @@ test('errors on loading config with incorrect default export', async () => {
let message = null;

try {
const cwd = join(__dirname, 'fixtures', 'export-string');
const cwd = join(import.meta.dirname, 'fixtures', 'export-string');
await load_config({ cwd });
} catch (/** @type {any} */ e) {
message = e.message;
Expand Down Expand Up @@ -505,7 +501,7 @@ test('errors on invalid forkPreloads values', () => {
});

test('uses src prefix for other kit.files options', async () => {
const cwd = join(__dirname, 'fixtures/custom-src');
const cwd = join(import.meta.dirname, 'fixtures/custom-src');

const config = await load_config({ cwd });
remove_keys(config, ([, v]) => typeof v === 'function');
Expand Down
48 changes: 36 additions & 12 deletions packages/kit/test/apps/dev-only/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { test } from '../../../utils.js';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

/** @typedef {import('@playwright/test').Response} Response */

Expand Down Expand Up @@ -86,7 +83,10 @@ test.describe('Vite', () => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest_path = path.join(
import.meta.dirname,
'../node_modules/.vite/deps/_metadata.json'
);
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).toHaveProperty('optimized.e2e-test-dep-page-svelte');
Expand All @@ -96,7 +96,10 @@ test.describe('Vite', () => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest_path = path.join(
import.meta.dirname,
'../node_modules/.vite/deps/_metadata.json'
);
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).toHaveProperty('optimized.e2e-test-dep-page-universal');
Expand All @@ -106,7 +109,10 @@ test.describe('Vite', () => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest_path = path.join(
import.meta.dirname,
'../node_modules/.vite/deps/_metadata.json'
);
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).not.toHaveProperty('optimized.e2e-test-dep-page-server');
Expand All @@ -116,7 +122,10 @@ test.describe('Vite', () => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest_path = path.join(
import.meta.dirname,
'../node_modules/.vite/deps/_metadata.json'
);
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).toHaveProperty('optimized.e2e-test-dep-layout-svelte');
Expand All @@ -126,7 +135,10 @@ test.describe('Vite', () => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest_path = path.join(
import.meta.dirname,
'../node_modules/.vite/deps/_metadata.json'
);
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).toHaveProperty('optimized.e2e-test-dep-layout-universal');
Expand All @@ -136,7 +148,10 @@ test.describe('Vite', () => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest_path = path.join(
import.meta.dirname,
'../node_modules/.vite/deps/_metadata.json'
);
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).not.toHaveProperty('optimized.e2e-test-dep-layout-server');
Expand All @@ -146,7 +161,10 @@ test.describe('Vite', () => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest_path = path.join(
import.meta.dirname,
'../node_modules/.vite/deps/_metadata.json'
);
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).toHaveProperty('optimized.e2e-test-dep-error');
Expand All @@ -156,7 +174,10 @@ test.describe('Vite', () => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest_path = path.join(
import.meta.dirname,
'../node_modules/.vite/deps/_metadata.json'
);
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).toHaveProperty('optimized.e2e-test-dep-hooks-client');
Expand All @@ -166,7 +187,10 @@ test.describe('Vite', () => {
await page.goto('/');
await page.getByText('hello world!').waitFor();

const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json');
const manifest_path = path.join(
import.meta.dirname,
'../node_modules/.vite/deps/_metadata.json'
);
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8'));

expect(manifest).toHaveProperty('optimized.e2e-test-dep-hooks');
Expand Down
4 changes: 1 addition & 3 deletions packages/kit/test/apps/options-2/test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { expect } from '@playwright/test';
import { test } from '../../../utils.js';

Expand Down Expand Up @@ -126,11 +125,10 @@ test.describe('trailing slash', () => {
test.describe('Service worker', () => {
if (process.env.DEV) {
test('import proxy /basepath/service-worker.js', async ({ request }) => {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const response = await request.get('/basepath/service-worker.js');
const content = await response.text();
expect(content).toEqual(
`import '${path.join('/basepath', '/@fs', __dirname, '../src/service-worker.js')}';`
`import '${path.join('/basepath', '/@fs', import.meta.dirname, '../src/service-worker.js')}';`
);
});

Expand Down
6 changes: 4 additions & 2 deletions packages/kit/test/apps/writes/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ test.describe('Filesystem updates', () => {
// future test file that has the same name
const route = 'zzzz' + Date.now();
const content = 'Hello new route';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const filepath = path.join(__dirname, `../src/routes/new-route/${route}/+page.svelte`);
const filepath = path.join(
import.meta.dirname,
`../src/routes/new-route/${route}/+page.svelte`
);
const dir = path.dirname(filepath);

try {
Expand Down
Loading
Loading