Skip to content

Commit

Permalink
feature: add getRoot helper function (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
levivilet authored Dec 24, 2024
1 parent f6ae3d5 commit 1255ae7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/test-integration/src/parts/GetRoot/GetRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getRoot = (): string => {
return new URL('../../../', import.meta.url).toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { expect, test } from '@jest/globals'
import getPort from 'get-port'
import { createPreviewProcess } from '../src/parts/CreatePreviewProcess/CreatePreviewProcess.js'
import { get } from '../src/parts/Get/Get.js'
import { getRoot } from '../src/parts/GetRoot/GetRoot.ts'

test('preview process - create and start server', async () => {
const previewProcess = createPreviewProcess()
const id = 1
const port = await getPort()
const root = new URL('../../../', import.meta.url)
const csp = "default-src 'self'; script-src 'self'"
const root = getRoot()

await previewProcess.invoke('WebViewServer.create', id)
await previewProcess.invoke('WebViewServer.setHandler', id, '', root, csp, '<h1>Hello World</h1>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { expect, test } from '@jest/globals'
import getPort from 'get-port'
import { createPreviewProcess } from '../src/parts/CreatePreviewProcess/CreatePreviewProcess.js'
import { get } from '../src/parts/Get/Get.js'
import { getRoot } from '../src/parts/GetRoot/GetRoot.js'

test('preview process - serves injected js', async () => {
const previewProcess = createPreviewProcess()
const id = 1
const port = await getPort()
const root = new URL('../../../', import.meta.url)
const root = getRoot()

await previewProcess.invoke('WebViewServer.create', id)
await previewProcess.invoke('WebViewServer.setHandler', id, '', root, '', '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { expect, test } from '@jest/globals'
import getPort from 'get-port'
import { createPreviewProcess } from '../src/parts/CreatePreviewProcess/CreatePreviewProcess.js'
import { get } from '../src/parts/Get/Get.js'
import { getRoot } from '../src/parts/GetRoot/GetRoot.js'

test('preview process - 404 for non-existent files', async () => {
const previewProcess = createPreviewProcess()
const id = 1
const port = await getPort()
const root = new URL('../../../', import.meta.url)
const root = getRoot()

await previewProcess.invoke('WebViewServer.create', id)
await previewProcess.invoke('WebViewServer.setHandler', id, '', root, '', '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { expect, test } from '@jest/globals'
import getPort from 'get-port'
import { createPreviewProcess } from '../src/parts/CreatePreviewProcess/CreatePreviewProcess.js'
import { get } from '../src/parts/Get/Get.js'
import { getRoot } from '../src/parts/GetRoot/GetRoot.js'

test('preview process - serve static files', async () => {
const previewProcess = createPreviewProcess()
const id = 1
const port = await getPort()
const root = new URL('../../../', import.meta.url)
const root = getRoot()

await previewProcess.invoke('WebViewServer.create', id)
await previewProcess.invoke('WebViewServer.setHandler', id, '', root, '', '')
Expand Down

0 comments on commit 1255ae7

Please sign in to comment.