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
4 changes: 2 additions & 2 deletions packages/dev-server-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"scripts": {
"build": "tsc",
"start": "wds --open --config demo/server.config.mjs",
"test:node": "mocha \"test/**/*.test.ts\" --require ts-node/register --reporter dot",
"test:watch": "mocha \"test/**/*.test.ts\" --require ts-node/register --watch --watch-files src,test"
"test:node": "node --experimental-strip-types --test --test-force-exit test/**/*.test.ts",
"test:watch": "node --experimental-strip-types --test --test-force-exit --watch test/**/*.test.ts"
},
"files": [
"*.d.ts",
Expand Down
25 changes: 12 additions & 13 deletions packages/dev-server-legacy/test/transform-html.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { expect } from 'chai';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { createTestServer } from '@web/dev-server-core/test-helpers';
import { fetchText, expectIncludes } from '@web/dev-server-core/test-helpers';

import { legacyPlugin } from '../src/legacyPlugin.js';
import { modernUserAgents, legacyUserAgents } from './userAgents.js';
import { legacyPlugin } from '../dist/legacyPlugin.js';
import { modernUserAgents, legacyUserAgents } from './userAgents.ts';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bennypowers I don't quite get now why we need to import from "dist" while we can import from ".ts"? your earlier reply #3097 (comment) now is not clear to me, I mean it's also a relative import, right? not sure what I am missing


const htmlBody = `
<html>
Expand All @@ -25,12 +26,10 @@ const inlineScriptHtmlBody = `
</body>
</html>`;

describe('legacyPlugin - transform html', function () {
this.timeout(10000);

describe('legacyPlugin - transform html', { timeout: 10000 }, () => {
it(`does not do any work on a modern browser`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
Expand All @@ -48,13 +47,13 @@ describe('legacyPlugin - transform html', function () {
headers: { 'user-agent': modernUserAgents['Chrome 78'] },
});

expect(text.trim()).to.equal(htmlBody.trim());
assert.equal(text.trim(), htmlBody.trim());
server.stop();
});

it(`injects polyfills into the HTML page on legacy browsers`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
Expand All @@ -80,7 +79,7 @@ describe('legacyPlugin - transform html', function () {

it(`injects systemjs param to inline modules`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
Expand All @@ -104,7 +103,7 @@ describe('legacyPlugin - transform html', function () {

it(`handles inline scripts`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
Expand All @@ -131,7 +130,7 @@ describe('legacyPlugin - transform html', function () {

it(`can request inline scripts`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
Expand All @@ -158,7 +157,7 @@ describe('legacyPlugin - transform html', function () {

it(`includes url parameters in inline script key`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
Expand Down
19 changes: 9 additions & 10 deletions packages/dev-server-legacy/test/transform-js.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { expect } from 'chai';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { createTestServer } from '@web/dev-server-core/test-helpers';
import { fetchText, expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers';

import { legacyPlugin } from '../src/legacyPlugin.js';
import { modernUserAgents, legacyUserAgents } from './userAgents.js';
import { legacyPlugin } from '../dist/legacyPlugin.js';
import { modernUserAgents, legacyUserAgents } from './userAgents.ts';

const modernCode = `
class Foo {
Expand All @@ -16,13 +17,11 @@ async function doImport() {

console.log(window?.foo?.bar);`;

describe('legacyPlugin - transform js', function () {
this.timeout(10000);

describe('legacyPlugin - transform js', { timeout: 10000 }, () => {
for (const [name, userAgent] of Object.entries(modernUserAgents)) {
it(`does not do any work on ${name}`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
Expand All @@ -39,15 +38,15 @@ describe('legacyPlugin - transform js', function () {
const text = await fetchText(`${host}/app.js`, {
headers: { 'user-agent': userAgent },
});
expect(text.trim()).to.equal(modernCode.trim());
assert.equal(text.trim(), modernCode.trim());
server.stop();
});
}

for (const [name, userAgent] of Object.entries(legacyUserAgents)) {
it(`transforms to es5 on ${name}`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
Expand Down Expand Up @@ -78,7 +77,7 @@ describe('legacyPlugin - transform js', function () {

it(`transforms to SystemJS when systemjs paramater is given ${name}`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
Expand Down
Loading