Skip to content

Commit 392b4f4

Browse files
authored
refactor: ipfs-gateway.js -> ipfs-gateway.ts (#669)
* chore: npm run test:all tests everything easily * refactor: ipfs-gateway.js -> ipfs-gateway.ts * chore: ensure start:hosted script uses correct ipfs-gateway.js path * chore: fix path to ipfs-gateway.js in playwright config * chore: some cleanup * chore: more cleanup
1 parent 3e43e90 commit 392b4f4

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
"build:esbuild": "node build.js",
1818
"start": "node build.js --watch --serve",
1919
"start:cloudflare": "npm run build && npx wrangler pages dev dist",
20-
"start:hosted": "concurrently --kill-others -c 'auto' -n 'app,gateway,proxy' \"npm run start\" \"wait-on 'http://localhost:8345' && cross-env PROXY_PORT=3334 GATEWAY_PORT=8088 POLL_INTERVAL=1000 node test-e2e/ipfs-gateway.js\" \"cross-env BACKEND_PORT=8345 PROXY_PORT=3333 node test-e2e/reverse-proxy.js\"",
20+
"prestart:hosted": "run-s build:tsc",
21+
"start:hosted": "concurrently --kill-others -c 'auto' -n 'app,gateway,proxy' \"npm run start\" \"wait-on 'http://localhost:8345' && cross-env PROXY_PORT=3334 GATEWAY_PORT=8088 POLL_INTERVAL=1000 node dist-tsc/test-e2e/ipfs-gateway.js\" \"cross-env BACKEND_PORT=8345 PROXY_PORT=3333 node dist-tsc/test-e2e/reverse-proxy.js\"",
2122
"test": "run-s test:iso 'test:node -- -b false'",
23+
"pretest:all": "run-s build",
24+
"test:all": "cross-env SHOULD_BUILD=false run-s 'test:iso -- -b false' 'test:node -- -b false' test:browsers",
2225
"test:iso": "aegir test -f dist-tsc/test/**/*.spec.js",
23-
"test:browsers": "playwright test -c playwright.config.js",
26+
"test:browsers": "playwright test -c playwright.config.js --project chromium firefox no-service-worker",
2427
"test:chrome": "playwright test -c playwright.config.js --project chromium",
2528
"test:no-sw": "playwright test -c playwright.config.js --project no-service-worker",
2629
"test:firefox": "playwright test -c playwright.config.js --project firefox --project no-service-worker",

playwright.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export default defineConfig({
9292
stderr: process.env.CI ? undefined : 'pipe'
9393
},
9494
{
95-
command: 'npx wait-on "http://localhost:3000" && node test-e2e/ipfs-gateway.js',
95+
command: 'npx wait-on "http://localhost:3000" && node dist-tsc/test-e2e/ipfs-gateway.js',
9696
timeout: 15 * 1000,
9797
env: {
9898
PROXY_PORT: '3334',
@@ -103,7 +103,7 @@ export default defineConfig({
103103
},
104104
{
105105
// need to use built assets due to service worker loading issue.
106-
command: 'npm run build && npx http-server --silent -p 3000 dist',
106+
command: process.env.SHOULD_BUILD !== 'false' ? 'npm run build && npx http-server --silent -p 3000 dist' : 'npx http-server --silent -p 3000 dist',
107107
port: 3000,
108108
timeout: 15 * 1000,
109109
reuseExistingServer: !process.env.CI,

test-e2e/ipfs-gateway.js renamed to test-e2e/ipfs-gateway.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { createReverseProxy } from './reverse-proxy.js'
1515
const log = logger('ipfs-host.local')
1616
const daemonLog = logger('ipfs-host.local:kubo')
1717
const proxyLog = logger('ipfs-host.local:proxy')
18+
// eslint-disable-next-line @typescript-eslint/naming-convention
1819
const __dirname = dirname(fileURLToPath(import.meta.url))
1920
const tempDir = tmpdir()
2021
const IPFS_PATH = `${tempDir}/.ipfs/${Date.now()}`
@@ -50,8 +51,8 @@ log('using IPFS_PATH: ', IPFS_PATH)
5051
const kuboRedirects = await readFile(join(cwd(), './dist/_kubo_redirects'), 'utf-8')
5152

5253
await writeFile(join(cwd(), './dist/_redirects'), kuboRedirects)
53-
54-
const { stdout: cid } = await $(execaOptions)`${kuboBin} add -r -Q ${relative(cwd(), '../dist')} --cid-version 1`
54+
const distPath = relative(cwd(), '../../dist')
55+
const { stdout: cid } = await $(execaOptions)`${kuboBin} add -r -Q ${distPath} --cid-version 1`
5556

5657
log('sw-gateway dist CID: ', cid.trim())
5758
const { stdout: pinStdout } = await $(execaOptions)`${kuboBin} pin add -r /ipfs/${cid.trim()}`
@@ -77,7 +78,7 @@ log('starting kubo')
7778
// need to stand up kubo daemon to serve the dist folder
7879
const daemon = execa(kuboBin, ['daemon', '--offline'], execaOptions)
7980

80-
if (daemon == null || (daemon.stdout == null || daemon.stderr == null)) {
81+
if (daemon.stdout == null || daemon.stderr == null) {
8182
throw new Error('failed to start kubo daemon')
8283
}
8384
daemon.stdout.on('data', (data) => {
@@ -89,7 +90,7 @@ daemon.stderr.on('data', (data) => {
8990

9091
// check for "daemon is ready" message
9192
await new Promise((resolve, reject) => {
92-
daemon.stdout?.on('data', (data) => {
93+
daemon.stdout?.on('data', (data: string) => {
9394
if (data.includes('Daemon is ready')) {
9495
// @ts-expect-error - nothing needed here.
9596
resolve()

0 commit comments

Comments
 (0)