mirror of
https://github.com/enso-org/enso.git
synced 2024-12-22 17:11:31 +03:00
3c31155fe9
- Implements https://github.com/enso-org/cloud-v2/issues/631 - Tests for dashboard (`app/ide-desktop/lib/dashboard/`): - End-to-end tests - Unit tests - Component tests The purpose of this PR is to introduce the testing framework - more tests can be added later in separate PRs. # Important Notes To test, run `npm run test` in `app/ide-desktop`, or `app/ide-desktop/lib/dashboard/`. All tests should pass. Individual test types can be run using `npm run test-unit`, `npm run test-component` and `npm run test-e2e` in `app/ide-desktop/lib/dashboard/`. Individual end-to-end tests can be run using `npx playwright test -c playwright-e2e.config.ts test-e2e/<file name>.spec.ts` in `app/ide-desktop/lib/dashboard/`. End-to-end tests require internet access to pass (for things like fonts). This PR *does* check in screenshots to guard against visual regessions (and/or to make visual changes obvious)
68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
/** @file File watch and compile service. */
|
|
import * as path from 'node:path'
|
|
import * as url from 'node:url'
|
|
|
|
import * as esbuild from 'esbuild'
|
|
import * as portfinder from 'portfinder'
|
|
import chalk from 'chalk'
|
|
|
|
import * as bundler from './esbuild-config'
|
|
import * as dashboardBundler from '../dashboard/esbuild-config'
|
|
|
|
// =================
|
|
// === Constants ===
|
|
// =================
|
|
|
|
/** The path of this file. */
|
|
const THIS_PATH = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)))
|
|
const PORT = 8080
|
|
const HTTP_STATUS_OK = 200
|
|
|
|
// ===============
|
|
// === Watcher ===
|
|
// ===============
|
|
|
|
/** Starts the esbuild watcher. */
|
|
async function watch() {
|
|
const dashboardOpts = dashboardBundler.bundleOptions()
|
|
const dashboardBuilder = await esbuild.context(dashboardOpts)
|
|
// We do not need to serve the dashboard as it outputs to the same directory.
|
|
// It will not rebuild on request, but it is not intended to rebuild on request anyway.
|
|
// This MUST be called before `builder.watch()` as `tailwind.css` must be generated
|
|
// before the copy plugin runs.
|
|
await dashboardBuilder.watch()
|
|
const opts = bundler.bundlerOptions(
|
|
bundler.argumentsFromEnv({
|
|
devMode: true,
|
|
supportsLocalBackend: true,
|
|
supportsDeepLinks: false,
|
|
})
|
|
)
|
|
opts.pure.splice(opts.pure.indexOf('assert'), 1)
|
|
;(opts.inject = opts.inject ?? []).push(path.resolve(THIS_PATH, '..', '..', 'debugGlobals.ts'))
|
|
opts.define['process.env.REDIRECT_OVERRIDE'] = JSON.stringify('http://localhost:8080')
|
|
// This is safe as this entry point is statically known.
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
const serviceWorkerEntryPoint = opts.entryPoints.find(
|
|
entryPoint => entryPoint.out === 'serviceWorker'
|
|
)!
|
|
serviceWorkerEntryPoint.in = path.resolve(THIS_PATH, 'src', 'devServiceWorker.ts')
|
|
const builder = await esbuild.context(opts)
|
|
await builder.watch()
|
|
await builder.serve({
|
|
port: await portfinder.getPortPromise({ port: PORT }),
|
|
servedir: opts.outdir,
|
|
/** This function is called on every request.
|
|
* It is used here to show an error if the file to serve was not found. */
|
|
onRequest(args) {
|
|
if (args.status !== HTTP_STATUS_OK) {
|
|
console.error(
|
|
chalk.red(`HTTP error ${args.status} when serving path '${args.path}'.`)
|
|
)
|
|
}
|
|
},
|
|
})
|
|
}
|
|
|
|
void watch()
|