Skip to content

Commit

Permalink
apply review
Browse files Browse the repository at this point in the history
x
  • Loading branch information
ShaMan123 committed Nov 11, 2023
1 parent d4c6f31 commit 1a74c72
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions e2e/tests/SSR/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { expect, test } from '@playwright/test';
import { exec, type ChildProcessWithoutNullStreams } from 'child_process';
import { spawn } from 'child_process';
import { readFileSync, watch } from 'fs';
import killPort from 'kill-port';
import path from 'path';
import type { Canvas } from '../../..';
import setupCoverage from '../../setup/setupCoverage';

setupCoverage();
Expand All @@ -15,15 +17,22 @@ test.describe('SSR', () => {
'next'
);

let task: ChildProcessWithoutNullStreams;
let disposer: VoidFunction;

test.beforeAll(({}, testInfo) => {
test.beforeAll(async ({}, testInfo) => {
testInfo.setTimeout(60 * 1000);
task = exec(`npm start next -- -p ${PORT} --no-watch`, {
await killPort(PORT);
// import `startSandbox` directly once ESM is supported
// https://playwright.dev/docs/release-notes#improved-typescript-support
const task = spawn(`npm start next -- -p ${PORT} --no-watch`, {
cwd: process.cwd(),
shell: true,
});
task.stdout.pipe(process.stdout);
task.stderr.pipe(process.stderr);
disposer = () => {
task.kill();
};
return new Promise<void>((resolve) => {
const watcher = watch(nextTemplateDir, (event, filename) => {
if (filename === '.instrumentation') {
Expand All @@ -34,7 +43,7 @@ test.describe('SSR', () => {
});
});

test.afterAll(() => task.kill());
test.afterAll(() => disposer());

test('SSR with Next.js', async ({ page }) => {
await page.goto(`http://localhost:${PORT}/`);
Expand All @@ -52,8 +61,23 @@ test.describe('SSR', () => {
await page.getByRole('textbox').press('Control+a');
await page
.getByRole('textbox')
.fill("fabric supports SSR!\nIsn't that amazing?!");
await page.waitForTimeout(50);
.fill('fabric can be used in SSR frameworks');
await page.evaluate(async () => {
// window.canvas is exposed in .codesandbox/templates/next/components/Canvas.tsx:33
const {
canvas,
} = // eslint-disable-next-line no-restricted-globals
window as Window & typeof globalThis & { canvas: Canvas };
const text = canvas.getActiveObject();
const text1 = await text.clone();
text1.set({ originX: 'left' });
text1.setX(0);
const text2 = await text.clone();
text2.set({ originX: 'right' });
// eslint-disable-next-line no-restricted-globals
text2.setX(window.innerWidth);
canvas.add(text1, text2);
});
expect(await page.screenshot()).toMatchSnapshot();
});

Expand Down
Binary file modified e2e/tests/SSR/index.spec.ts-snapshots/SSR-SSR-with-Next-js-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1a74c72

Please sign in to comment.