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
5 changes: 1 addition & 4 deletions packages/dev-server-rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"node": ">=22.0.0"
},
"scripts": {
"test:node": "mocha \"test/node/**/*.test.ts\" --require ts-node/register --exit --reporter dot",
"test:watch": "mocha \"test/node/**/*.test.ts\" --require ts-node/register --watch --watch-files src,test"
"test:node": "node --experimental-strip-types --test --test-force-exit 'test/node/**/*.test.ts'"
},
"files": [
"*.d.ts",
Expand Down Expand Up @@ -65,8 +64,6 @@
"@types/whatwg-url": "^11.0.0",
"@web/test-runner-chrome": "^0.18.0",
"@web/test-runner-core": "^0.13.0",
"chai": "^4.2.0",
"mocha": "^10.8.2",
"postcss": "^8.5.14",
"rollup-plugin-postcss": "^4.0.2"
}
Expand Down
5 changes: 3 additions & 2 deletions packages/dev-server-rollup/test/node/plugins/alias.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, it } from 'node:test';
import rollupAlias from '@rollup/plugin-alias';

import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
import { fromRollup } from '../../../src/fromRollup.js';
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../dist/fromRollup.js';

const alias = fromRollup(rollupAlias);

Expand Down
8 changes: 6 additions & 2 deletions packages/dev-server-rollup/test/node/plugins/babel.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/// <reference types="../../../types/rollup__plugin-babel" />
import { describe, it } from 'node:test';
import { createRequire } from 'node:module';
import rollupBabel from '@rollup/plugin-babel';

import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
import { fromRollup } from '../../../src/index.js';
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../dist/index.js';

const require = createRequire(import.meta.url);

const babel = fromRollup(rollupBabel);

Expand Down
15 changes: 8 additions & 7 deletions packages/dev-server-rollup/test/node/plugins/commonjs.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { describe, it } from 'node:test';
import rollupCommonjs from '@rollup/plugin-commonjs';
import { runTests } from '@web/test-runner-core/test-helpers';
import { resolve } from 'path';
import { chromeLauncher } from '@web/test-runner-chrome';

import * as path from 'path';
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
import { fromRollup } from '../../../src/index.js';
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../dist/index.js';
import { nodeResolvePlugin } from '@web/dev-server';

const commonjs = fromRollup(rollupCommonjs);
Expand Down Expand Up @@ -140,7 +141,7 @@ exports.default = _default;`;
});

it('can transform modules which require node-resolved modules', async () => {
const rootDir = path.resolve(__dirname, '..', 'fixtures', 'basic');
const rootDir = path.resolve(import.meta.dirname, '..', 'fixtures', 'basic');
const { server, host } = await createTestServer({
plugins: [
{
Expand Down Expand Up @@ -199,11 +200,11 @@ exports.default = _default;`;
}
});

it('passes the in-browser tests', async function () {
this.timeout(40000);

it('passes the in-browser tests', { timeout: 40000 }, async () => {
await runTests({
files: [resolve(__dirname, '..', 'fixtures', 'commonjs', 'commonjs-browser-test.js')],
files: [
resolve(import.meta.dirname, '..', 'fixtures', 'commonjs', 'commonjs-browser-test.js'),
],
browsers: [chromeLauncher({ launchOptions: { devtools: false } })],
plugins: [
fromRollup(rollupCommonjs)({
Expand Down
23 changes: 12 additions & 11 deletions packages/dev-server-rollup/test/node/plugins/node-resolve.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import path from 'path';
import rollupNodeResolve from '@rollup/plugin-node-resolve';
import rollupCommonjs from '@rollup/plugin-commonjs';

import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
import { fromRollup } from '../../../src/index.js';
import { expect } from 'chai';
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../dist/index.js';

const nodeResolve = fromRollup(rollupNodeResolve, {}, { throwOnUnresolvedImport: true });
const commonjs = fromRollup(rollupCommonjs);
Expand Down Expand Up @@ -61,7 +62,7 @@ describe('@rollup/plugin-node-resolve', () => {

it('can resolve private imports in inline scripts', async () => {
const { server, host } = await createTestServer({
rootDir: path.resolve(__dirname, '..', 'fixtures', 'private-imports'),
rootDir: path.resolve(import.meta.dirname, '..', 'fixtures', 'private-imports'),
plugins: [nodeResolve()],
});

Expand All @@ -76,13 +77,13 @@ describe('@rollup/plugin-node-resolve', () => {

it('throws when trying to access files from the package directly if they are not exposed in the export map', async () => {
const { server, host } = await createTestServer({
rootDir: path.resolve(__dirname, '..', 'fixtures', 'private-imports'),
rootDir: path.resolve(import.meta.dirname, '..', 'fixtures', 'private-imports'),
plugins: [nodeResolve()],
});

try {
const response = await fetch(`${host}/import-private-directly.html`);
expect(response.status).to.equal(500);
assert.equal(response.status, 500);
} finally {
server.stop();
}
Expand All @@ -105,7 +106,7 @@ describe('@rollup/plugin-node-resolve', () => {

try {
const response = await fetch(`${host}/test-app.js`);
expect(response.status).to.equal(500);
assert.equal(response.status, 500);
} finally {
server.stop();
}
Expand All @@ -128,15 +129,15 @@ describe('@rollup/plugin-node-resolve', () => {

try {
const text = await fetchText(`${host}/test-app.js`);
expect(text).to.equal('import "/non-existing.js"; import "./src/non-existing.js";');
assert.equal(text, 'import "/non-existing.js"; import "./src/non-existing.js";');
} finally {
server.stop();
}
});

it('node modules resolved outside root directory with matching basename via symlink are rewritten', async () => {
const { server, host } = await createTestServer({
rootDir: path.resolve(__dirname, '..', 'fixtures', 'resolve-outside-dir'),
rootDir: path.resolve(import.meta.dirname, '..', 'fixtures', 'resolve-outside-dir'),
plugins: [nodeResolve()],
});

Expand All @@ -153,7 +154,7 @@ describe('@rollup/plugin-node-resolve', () => {

it('node modules resolved outside root directory are rewritten', async () => {
const { server, host } = await createTestServer({
rootDir: path.resolve(__dirname, '..', 'fixtures', 'resolve-outside-dir', 'src'),
rootDir: path.resolve(import.meta.dirname, '..', 'fixtures', 'resolve-outside-dir', 'src'),
plugins: [nodeResolve()],
});

Expand All @@ -170,7 +171,7 @@ describe('@rollup/plugin-node-resolve', () => {

it('node modules resolved outside root directory are rewritten with commonjs', async () => {
const { server, host } = await createTestServer({
rootDir: path.resolve(__dirname, '..', 'fixtures', 'resolve-outside-dir', 'src'),
rootDir: path.resolve(import.meta.dirname, '..', 'fixtures', 'resolve-outside-dir', 'src'),
plugins: [commonjs(), nodeResolve()],
});

Expand Down
12 changes: 6 additions & 6 deletions packages/dev-server-rollup/test/node/plugins/postcss.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/// <reference types="../../../types/rollup-plugin-postcss" />
import { describe, it } from 'node:test';
import rollupPostcss from 'rollup-plugin-postcss';
import { chromeLauncher } from '@web/test-runner-chrome';
import { runTests } from '@web/test-runner-core/test-helpers';
import { resolve } from 'path';

import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
import { fromRollup } from '../../../src/index.js';
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../dist/index.js';

const postcss = fromRollup(rollupPostcss);

describe('@rollup/plugin-postcss', () => {
it('can run postcss on imported css files', async () => {
const { server, host } = await createTestServer({
rootDir: resolve(__dirname, '..', '..', '..', '..', '..'),
rootDir: resolve(import.meta.dirname, '..', '..', '..', '..', '..'),
mimeTypes: {
'**/*.css': 'js',
},
Expand Down Expand Up @@ -57,10 +58,9 @@ html {
}
});

it('passes the in-browser tests', async function () {
this.timeout(40000);
it('passes the in-browser tests', { timeout: 40000 }, async () => {
await runTests({
files: [resolve(__dirname, '..', 'fixtures', 'postcss', 'postcss-browser-test.js')],
files: [resolve(import.meta.dirname, '..', 'fixtures', 'postcss', 'postcss-browser-test.js')],
browsers: [chromeLauncher()],
mimeTypes: {
'**/*.css': 'js',
Expand Down
5 changes: 3 additions & 2 deletions packages/dev-server-rollup/test/node/plugins/replace.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, it } from 'node:test';
import rollupReplace from '@rollup/plugin-replace';

import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
import { fromRollup } from '../../../src/index.js';
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../dist/index.js';

const replace = fromRollup(rollupReplace as any);

Expand Down
25 changes: 13 additions & 12 deletions packages/dev-server-rollup/test/node/rollupBundlePlugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { rollupBundlePlugin } from '../../src/rollupBundlePlugin.js';
import { describe, it } from 'node:test';
import { rollupBundlePlugin } from '../../dist/rollupBundlePlugin.js';
import path from 'path';
import { createTestServer, fetchText, expectIncludes } from './test-helpers.js';
import { createTestServer, fetchText, expectIncludes } from './test-helpers.ts';

describe('rollupBundlePlugin', () => {
it('can bundle a single entrypoint', async () => {
const { server, host } = await createTestServer({
rootDir: path.join(__dirname, 'fixtures', 'bundle-basic'),
rootDir: path.join(import.meta.dirname, 'fixtures', 'bundle-basic'),
plugins: [
rollupBundlePlugin({
rollupConfig: {
input: path.join(__dirname, 'fixtures', 'bundle-basic', 'a.js'),
input: path.join(import.meta.dirname, 'fixtures', 'bundle-basic', 'a.js'),
},
}),
],
Expand All @@ -28,14 +29,14 @@ describe('rollupBundlePlugin', () => {

it('can bundle multiple entrypoint', async () => {
const { server, host } = await createTestServer({
rootDir: path.join(__dirname, 'fixtures', 'bundle-multi'),
rootDir: path.join(import.meta.dirname, 'fixtures', 'bundle-multi'),
plugins: [
rollupBundlePlugin({
rollupConfig: {
input: [
path.join(__dirname, 'fixtures', 'bundle-multi', 'a1.js'),
path.join(__dirname, 'fixtures', 'bundle-multi', 'a2.js'),
path.join(__dirname, 'fixtures', 'bundle-multi', 'a3.js'),
path.join(import.meta.dirname, 'fixtures', 'bundle-multi', 'a1.js'),
path.join(import.meta.dirname, 'fixtures', 'bundle-multi', 'a2.js'),
path.join(import.meta.dirname, 'fixtures', 'bundle-multi', 'a3.js'),
],
output: {
chunkFileNames: '[name].js',
Expand Down Expand Up @@ -73,11 +74,11 @@ describe('rollupBundlePlugin', () => {

it('can serve regular files not bundled by rollup', async () => {
const { server, host } = await createTestServer({
rootDir: path.join(__dirname, 'fixtures', 'bundle-basic'),
rootDir: path.join(import.meta.dirname, 'fixtures', 'bundle-basic'),
plugins: [
rollupBundlePlugin({
rollupConfig: {
input: path.join(__dirname, 'fixtures', 'bundle-basic', 'a.js'),
input: path.join(import.meta.dirname, 'fixtures', 'bundle-basic', 'a.js'),
},
}),
],
Expand All @@ -94,11 +95,11 @@ describe('rollupBundlePlugin', () => {

it('can serve files emitted by a rollup plugin', async () => {
const { server, host } = await createTestServer({
rootDir: path.join(__dirname, 'fixtures', 'bundle-basic'),
rootDir: path.join(import.meta.dirname, 'fixtures', 'bundle-basic'),
plugins: [
rollupBundlePlugin({
rollupConfig: {
input: path.join(__dirname, 'fixtures', 'bundle-basic', 'a.js'),
input: path.join(import.meta.dirname, 'fixtures', 'bundle-basic', 'a.js'),
plugins: [
{
name: 'file-plugin',
Expand Down
4 changes: 2 additions & 2 deletions packages/dev-server-rollup/test/node/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
fetchText,
expectIncludes,
} from '@web/dev-server-core/test-helpers';
import { DevServerCoreConfig, Logger } from '@web/dev-server-core';
import type { DevServerCoreConfig, Logger } from '@web/dev-server-core';

export function createTestServer(config: Partial<DevServerCoreConfig> = {}, mockLogger?: Logger) {
return originalCreateTestServer(
{
rootDir: path.resolve(__dirname, 'fixtures', 'basic'),
rootDir: path.resolve(import.meta.dirname, 'fixtures', 'basic'),
...config,
},
mockLogger,
Expand Down
Loading
Loading