Skip to content
Merged
Prev Previous commit
Next Next commit
setup script with build and serve
  • Loading branch information
Tobbe committed Sep 25, 2023
commit 55436d025b6b0ff15a9074b02b5a4f709d8522bf
8 changes: 1 addition & 7 deletions tasks/smoke-tests/basePlaywright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import * as fs from 'node:fs'
import type { PlaywrightTestConfig } from '@playwright/test'
import { devices } from '@playwright/test'

if (fs.existsSync('./tests/global.setup.ts')) {
console.log('adding setup step')
}

// See https://playwright.dev/docs/test-configuration#global-configuration
export const basePlaywrightConfig: PlaywrightTestConfig = {
testDir: './tests',
Expand All @@ -24,9 +20,7 @@ export const basePlaywrightConfig: PlaywrightTestConfig = {
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
dependencies: fs.existsSync('./tests/global.setup.ts')
? ['setup']
: undefined,
dependencies: fs.existsSync('./tests/setup.ts') ? ['setup'] : undefined,
},

// {
Expand Down
21 changes: 10 additions & 11 deletions tasks/smoke-tests/rsc/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { defineConfig } from '@playwright/test'

import { basePlaywrightConfig } from '../basePlaywright.config'

export const projectData = {
serveProcess: undefined,
}

// See https://playwright.dev/docs/test-configuration#global-configuration
export default defineConfig({
...basePlaywrightConfig,
Expand All @@ -10,21 +14,16 @@ export default defineConfig({
...basePlaywrightConfig.projects,
{
name: 'setup',
testMatch: /global\.setup\.ts/,
testMatch: 'setup.ts',
teardown: 'kill server',
},
{
name: 'kill server',
testMatch: 'teardown.ts',
},
],

use: {
baseURL: 'http://localhost:8910',
},

// Run your local dev server before starting the tests if you want to test
// against that instead of spinning up a new server
webServer: {
command: 'yarn redwood serve',
cwd: process.env.REDWOOD_TEST_PROJECT_PATH,
url: 'http://localhost:8910',
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
},
})
108 changes: 0 additions & 108 deletions tasks/smoke-tests/rsc/tests/global.setup.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { test as setup } from '@playwright/test'
// @ts-expect-error - With `* as` you have to use .default() when calling execa
import execa from 'execa'

import { projectData } from '../playwright.config'

class ExecaError extends Error {
stdout: string
stderr: string
Expand Down Expand Up @@ -70,19 +72,16 @@ async function createTestProject() {
// const cmd = `node ./packages/create-redwood-app/dist/create-redwood-app.js --yes ${projectOutputPath}`
const cmd = `npx -y create-redwood-app@canary -y ${projectOutputPath}`

await exec(cmd, getExecaOptions(rwPath))
await exec(cmd, getExecaOptions('/'))

return projectOutputPath
}

async function setupRsc(projectOutputPath: string) {
const rwPath = path.resolve(__dirname, '../../..')
console.log('rwPath', rwPath)
const rwPath = path.resolve(__dirname, '../../../..')
const rwBinPath = path.join(rwPath, 'packages/cli/dist/index.js')
console.log('rwBinPath', rwBinPath)

const cmdSetupStreamingSSR = `node ${rwBinPath} experimental setup-streaming-ssr -f`
console.log('cmdSetupStreamingSSR', cmdSetupStreamingSSR)
await exec(cmdSetupStreamingSSR, getExecaOptions(projectOutputPath))

const cmdSetupRSC = `node ${rwBinPath} experimental setup-rsc`
Expand All @@ -97,16 +96,21 @@ async function build(projectOutputPath: string) {
await exec(cmdBuild, getExecaOptions(projectOutputPath))
}

async function serve(projectOutputPath: string) {
const rwPath = path.resolve(__dirname, '../../../..')
const rwBinPath = path.join(rwPath, 'packages/cli/dist/index.js')

const cmdBuild = `node ${rwBinPath} serve`
return exec(cmdBuild, getExecaOptions(projectOutputPath))
}

setup('Setup and build test project', async () => {
// Allow ample time for yarn to install everything
setup.setTimeout(5 * 60 * 1000)

console.log('setup and build test project')
const projectOutputPath = await createTestProject()
await setupRsc(projectOutputPath)
await build(projectOutputPath)
const serveProcess = serve(projectOutputPath)
projectData.serveProcess = serveProcess
})

console.log('global.setup.ts')
console.log('global.setup.ts')
console.log('global.setup.ts')
10 changes: 10 additions & 0 deletions tasks/smoke-tests/rsc/tests/teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { test as setup } from '@playwright/test'

import { projectData } from '../playwright.config'

setup('Kill server', async () => {
// Allow ample time for yarn to install everything
setup.setTimeout(5 * 60 * 1000)

console.log('pid', projectData.serveProcess.pid)
})