Skip to content

Commit

Permalink
test: update test server/paths
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 3, 2022
1 parent 981abbe commit a82ca33
Show file tree
Hide file tree
Showing 42 changed files with 74 additions and 106 deletions.
4 changes: 0 additions & 4 deletions scripts/build-atomics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { RollupOptions } from 'rollup';
import {
BuildOptions,
copyOutputToTests,
fileSize,
jsBannerPlugin,
syncCommunicationModulesPlugin,
Expand All @@ -10,7 +9,6 @@ import {
} from './utils';
import { join } from 'path';
import { minifyPlugin } from './minify';
import { writeFile } from 'fs-extra';
import { webWorkerBlobUrlPlugin } from './build-web-worker';

export function buildAtomics(opts: BuildOptions): RollupOptions[] {
Expand Down Expand Up @@ -41,7 +39,6 @@ function buildAtomicsDebug(opts: BuildOptions): RollupOptions {
webWorkerBlobUrlPlugin(opts, 'atomics', true),
watchDir(opts, join(opts.tscLibDir, 'atomics')),
watchDir(opts, join(opts.tscLibDir, 'web-worker')),
copyOutputToTests(opts),
jsBannerPlugin(opts),
],
};
Expand All @@ -63,7 +60,6 @@ function buildAtomicsMin(opts: BuildOptions): RollupOptions {
webWorkerBlobUrlPlugin(opts, 'atomics', false),
watchDir(opts, join(opts.tscLibDir, 'atomics')),
watchDir(opts, join(opts.tscLibDir, 'web-worker')),
copyOutputToTests(opts),
versionPlugin(opts),
jsBannerPlugin(opts),
],
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-main-snippet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BuildOptions, copyOutputToTests, fileSize, jsBannerPlugin, versionPlugin } from './utils';
import { BuildOptions, fileSize, jsBannerPlugin, versionPlugin } from './utils';
import { join } from 'path';
import { minifyPlugin } from './minify';
import type { OutputOptions, RollupOptions } from 'rollup';
Expand Down Expand Up @@ -40,6 +40,6 @@ export function buildMainSnippet(opts: BuildOptions): RollupOptions {
return {
input: join(opts.tscLibDir, 'main', 'snippet-entry.js'),
output,
plugins: [jsBannerPlugin(opts), copyOutputToTests(opts)],
plugins: [jsBannerPlugin(opts)],
};
}
15 changes: 2 additions & 13 deletions scripts/build-media-implementations.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import type { OutputOptions, RollupOptions } from 'rollup';
import {
BuildOptions,
copyOutputToTests,
fileSize,
jsBannerPlugin,
versionPlugin,
watchDir,
} from './utils';
import { BuildOptions, fileSize, jsBannerPlugin, versionPlugin, watchDir } from './utils';
import { join } from 'path';
import { minifyPlugin } from './minify';

Expand Down Expand Up @@ -35,10 +28,6 @@ export function buildMediaImplementation(opts: BuildOptions): RollupOptions {
return {
input: join(opts.tscLibDir, 'web-worker', 'media', 'index.js'),
output,
plugins: [
watchDir(opts, join(opts.tscLibDir, 'web-worker', 'media')),
jsBannerPlugin(opts),
copyOutputToTests(opts),
],
plugins: [watchDir(opts, join(opts.tscLibDir, 'web-worker', 'media')), jsBannerPlugin(opts)],
};
}
3 changes: 0 additions & 3 deletions scripts/build-service-worker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { OutputOptions, Plugin, rollup, RollupOptions } from 'rollup';
import {
BuildOptions,
copyOutputToTests,
fileSize,
jsBannerPlugin,
MessageType,
Expand Down Expand Up @@ -40,7 +39,6 @@ export function buildServiceWorker(opts: BuildOptions): RollupOptions {
sandboxContentPlugin(opts, 'sw'),
watchDir(opts, join(opts.tscLibDir, 'sandbox')),
watchDir(opts, join(opts.tscLibDir, 'web-worker')),
copyOutputToTests(opts),
jsBannerPlugin(opts),
],
};
Expand Down Expand Up @@ -71,7 +69,6 @@ async function buildSandboxServiceWorker(opts: BuildOptions, msgType: MessageTyp
if (debug) {
const outName = `partytown-sandbox-${msgType}.js`;
await writeFile(join(opts.distLibDebugDir, outName), sandboxJsCode);
await writeFile(join(opts.distTestsLibDebugDir, outName), sandboxJsCode);
sandboxHtml = `<!DOCTYPE html><html><head><meta charset="utf-8"><script src="./partytown-sandbox-${msgType}.js"></script></head></html>`;
} else {
sandboxHtml = `<!DOCTYPE html><html><head><meta charset="utf-8"><script type="module">${sandboxJsCode}</script></head></html>`;
Expand Down
1 change: 0 additions & 1 deletion scripts/build-web-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export async function buildWebWorker(opts: BuildOptions, msgType: MessageType, d
if (debug) {
const outName = `partytown-ww-${msgType}.js`;
await writeFile(join(opts.distLibDebugDir, outName), webWorkerCode);
await writeFile(join(opts.distTestsLibDebugDir, outName), webWorkerCode);
}

return webWorkerCode;
Expand Down
7 changes: 0 additions & 7 deletions scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,14 @@ async function createRootPackage(opts: BuildOptions) {
await ensureDir(opts.distIntegrationDir);
await ensureDir(opts.distServicesDir);
await ensureDir(opts.distLibDir);
await ensureDir(opts.distTestsLibDir);
await ensureDir(opts.distReactDir);
} else {
await emptyDir(opts.distIntegrationDir);
await emptyDir(opts.distServicesDir);
await emptyDir(opts.distLibDir);
await emptyDir(opts.distTestsLibDir);
await emptyDir(opts.distReactDir);
}
await ensureDir(opts.distLibDebugDir);
await emptyDir(opts.distTestsLibDebugDir);

const indexCjsPath = join(opts.rootDir, 'index.cjs');
const indexMjsPath = join(opts.rootDir, 'index.mjs');
Expand Down Expand Up @@ -77,8 +74,6 @@ function createBuildOptions(rootDir: string, isDev: boolean, generateApi: boolea

const testsDir = join(rootDir, 'tests');
const testsVideosDir = join(testsDir, 'videos');
const distTestsLibDir = join(testsDir, '~partytown');
const distTestsLibDebugDir = join(distTestsLibDir, 'debug');

const tscDir = join(rootDir, 'tsc');
const tscSrcDir = join(tscDir, 'src');
Expand All @@ -101,8 +96,6 @@ function createBuildOptions(rootDir: string, isDev: boolean, generateApi: boolea
distServicesDir,
distLibDir,
distLibDebugDir,
distTestsLibDir,
distTestsLibDebugDir,
distReactDir,
distUtilsDir,

Expand Down
2 changes: 1 addition & 1 deletion scripts/serve.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ const enableAtomics = process.argv.includes('--atomics');

(async () => {
const server = await createServer(port, enableAtomics);
console.log(`Serving${server.enableAtomics ? ` (atomics)` : ``}: ${server.address}`);
console.log(`Serving${server.enableAtomics ? ` (atomics)` : ``}: ${server.address}tests/`);
})();
14 changes: 10 additions & 4 deletions scripts/server.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ const http = require('http');
const fs = require('fs');

exports.createServer = function (port, enableAtomics) {
const testsDir = path.join(__dirname, '..', 'tests');
const rootDir = path.join(__dirname, '..');
const address = `http://localhost:${port}/`;

const server = http.createServer(async (req, rsp) => {
const url = new URL(req.url, address);
let filePath = path.join(testsDir, url.pathname.substring(1));
if (url.pathname.endsWith('/')) {
filePath = path.join(filePath, 'index.html');
const pathName = url.pathname.substring(1);
let filePath;

if (pathName.startsWith('~partytown')) {
filePath = path.join(rootDir, 'lib', pathName.replace('~partytown/', ''));
} else if (pathName.endsWith('/')) {
filePath = path.join(rootDir, pathName, 'index.html');
} else {
filePath = path.join(rootDir, pathName);
}

if (url.searchParams.has('delay')) {
Expand Down
18 changes: 2 additions & 16 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gzipSize from 'gzip-size';
import { basename, relative, resolve, join } from 'path';
import { copyFile, readdirSync, readFileSync, readJson, statSync, writeJson } from 'fs-extra';
import { basename, join } from 'path';
import { readdirSync, readFileSync, readJson, statSync, writeJson } from 'fs-extra';
import type { Plugin, RollupWarning } from 'rollup';

export function syncCommunicationModulesPlugin(opts: BuildOptions, msgType: MessageType): Plugin {
Expand Down Expand Up @@ -104,18 +104,6 @@ export function watchDir(opts: BuildOptions, dir: string): Plugin {
};
}

export function copyOutputToTests(opts: BuildOptions): Plugin {
return {
name: 'copyOutputToTests',
async writeBundle(writeOpts) {
const src = writeOpts.file!;
const rel = relative(opts.distLibDir, writeOpts.file!);
const dest = resolve(opts.distTestsLibDir, rel);
await copyFile(src, dest);
},
};
}

export function onwarn(warning: RollupWarning) {
if (warning.code === 'CIRCULAR_DEPENDENCY') return;
console.log(warning.code);
Expand Down Expand Up @@ -161,8 +149,6 @@ export interface BuildOptions {
distLibDir: string;
distLibDebugDir: string;
distServicesDir: string;
distTestsLibDir: string;
distTestsLibDebugDir: string;
distReactDir: string;
distUtilsDir: string;
srcDir: string;
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmarks/run.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function runBenchmark(browserType, isBaseline, label) {
const page = await browser.newPage();
await page.setViewportSize({ width: 360, height: 360 });

const url = new URL('/benchmarks/', server.address);
const url = new URL('/tests/benchmarks/', server.address);
if (isBaseline) {
url.searchParams.set('baseline', '');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/adobe-launch/adobe-launch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('adobe-launch', async ({ page }) => {
await page.goto('/integrations/adobe-launch/');
await page.goto('/tests/integrations/adobe-launch/');

const btnTrack = page.locator('#track');
await btnTrack.click();
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/config/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('integration config', async ({ page }) => {
await page.goto('/integrations/config/');
await page.goto('/tests/integrations/config/');
await page.waitForSelector('.completed');

const testGetContinue = page.locator('#testGetContinue');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('integration event forwarding', async ({ page }) => {
await page.goto('/integrations/event-forwarding/');
await page.goto('/tests/integrations/event-forwarding/');
await page.waitForSelector('.completed');

const testFn = page.locator('#testFn');
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/facebook-pixel/facebook-pixel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('facebook-pixel', async ({ page }) => {
await page.goto('/integrations/facebook-pixel/');
await page.goto('/tests/integrations/facebook-pixel/');

await page.waitForSelector('.completed');

Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/gtm/gtm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('gtm', async ({ page }) => {
await page.goto('/integrations/gtm/');
await page.goto('/tests/integrations/gtm/');

await page.waitForSelector('.completed');

Expand Down
2 changes: 1 addition & 1 deletion tests/nextjs/nextjs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('nextjs', async ({ page }) => {
await page.goto('/');
await page.goto('/tests/');

await page.waitForSelector('.completed');

Expand Down
8 changes: 4 additions & 4 deletions tests/platform/anchor/anchor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { test, expect } from '@playwright/test';

test('anchor', async ({ page }) => {
await page.goto('/platform/anchor/');
await page.goto('/tests/platform/anchor/');

await page.waitForSelector('.testAnchor');
const testAnchor = page.locator('#testAnchor');
await expect(testAnchor).toHaveText('/platform/anchor/some/other/path');
await expect(testAnchor).toHaveText('/tests/platform/anchor/some/other/path');

await page.waitForSelector('.testAnchorConstructor');
const testAnchorConstructor = page.locator('#testAnchorConstructor');
await expect(testAnchorConstructor).toHaveText('HTMLAnchorElement HTMLAnchorElement');

await page.waitForSelector('.testCreateAnchorNoAppend');
const testCreateAnchorNoAppend = page.locator('#testCreateAnchorNoAppend');
await expect(testCreateAnchorNoAppend).toHaveText('/platform/anchor/no-append-child');
await expect(testCreateAnchorNoAppend).toHaveText('/tests/platform/anchor/no-append-child');

await page.waitForSelector('.testCreateAnchorAppend');
const testCreateAnchorAppend = page.locator('#testCreateAnchorAppend');
await expect(testCreateAnchorAppend).toHaveText('/platform/anchor/append-child');
await expect(testCreateAnchorAppend).toHaveText('/tests/platform/anchor/append-child');

await page.waitForSelector('.testInnerHtmlFirstChild');
const testInnerHtmlFirstChild = page.locator('#testInnerHtmlFirstChild');
Expand Down
2 changes: 1 addition & 1 deletion tests/platform/audio/audio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test('audio', async ({ page }) => {
return;
}

await page.goto('/platform/audio/');
await page.goto('/tests/platform/audio/');

page.on('console', (msg) => {
if (msg.type() === 'error') {
Expand Down
2 changes: 1 addition & 1 deletion tests/platform/canvas/canvas.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('canvas', async ({ page }) => {
await page.goto('/platform/canvas/');
await page.goto('/tests/platform/canvas/');

await page.waitForSelector('.completed');

Expand Down
6 changes: 3 additions & 3 deletions tests/platform/document-prod/document-prod.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('document-prod', async ({ page }) => {
await page.goto('/platform/document-prod/');
await page.goto('/tests/platform/document-prod/');

await page.waitForSelector('.completed');

Expand All @@ -27,7 +27,7 @@ test('document-prod', async ({ page }) => {
await expect(testCookie).toHaveText('mph=88');

const testLocationGet = page.locator('#testLocationGet');
await expect(testLocationGet).toHaveText('/platform/document-prod/');
await expect(testLocationGet).toHaveText('/tests/platform/document-prod/');

const testDefaultView = page.locator('#testDefaultView');
await expect(testDefaultView).toHaveText('window');
Expand All @@ -51,7 +51,7 @@ test('document-prod', async ({ page }) => {
const testCurrentScriptSrcLocation = page.locator('#testCurrentScriptSrcLocation');
await expect(testCurrentScriptSrc).toHaveText('src');
await expect(testCurrentScriptSrcLocation).toHaveText(
'/platform/document-prod/current-script-src.js'
'/tests/platform/document-prod/current-script-src.js'
);

const testDocCstrName = page.locator('#testDocCstrName');
Expand Down
8 changes: 5 additions & 3 deletions tests/platform/document/document.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('document', async ({ page }) => {
await page.goto('/platform/document/');
await page.goto('/tests/platform/document/');

await page.waitForSelector('.completed');

Expand All @@ -27,7 +27,7 @@ test('document', async ({ page }) => {
await expect(testCookie).toHaveText('mph=88');

const testLocationGet = page.locator('#testLocationGet');
await expect(testLocationGet).toHaveText('/platform/document/');
await expect(testLocationGet).toHaveText('/tests/platform/document/');

const testDefaultView = page.locator('#testDefaultView');
await expect(testDefaultView).toHaveText('window');
Expand All @@ -50,7 +50,9 @@ test('document', async ({ page }) => {
const testCurrentScriptSrc = page.locator('#testCurrentScriptSrc');
const testCurrentScriptSrcLocation = page.locator('#testCurrentScriptSrcLocation');
await expect(testCurrentScriptSrc).toHaveText('src');
await expect(testCurrentScriptSrcLocation).toHaveText('/platform/document/current-script-src.js');
await expect(testCurrentScriptSrcLocation).toHaveText(
'/tests/platform/document/current-script-src.js'
);

await page.waitForSelector('.testCurrentScriptNullAsync');
const testCurrentScriptNullAsync = page.locator('#testCurrentScriptNullAsync');
Expand Down
2 changes: 1 addition & 1 deletion tests/platform/element-class/element-class.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('element class', async ({ page }) => {
await page.goto('/platform/element-class/');
await page.goto('/tests/platform/element-class/');
await page.waitForSelector('.completed');

const testClassname = page.locator('#testClassname');
Expand Down
2 changes: 1 addition & 1 deletion tests/platform/element-style/element-style.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('element style', async ({ page }) => {
await page.goto('/platform/element-style/');
await page.goto('/tests/platform/element-style/');
await page.waitForSelector('.completed');

const testColor = page.locator('#testColor');
Expand Down

1 comment on commit a82ca33

@vercel
Copy link

@vercel vercel bot commented on a82ca33 Feb 3, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.