Skip to content
Source
Sign inSign up
samwillis/neon-realtime-electric
Open History to see the last commit

test-integration-packages.mjs

110 lines3.2 KB

1import assert from 'node:assert/strict'
2import { spawnSync } from 'node:child_process'
3import { cp, mkdir, readdir, rm, writeFile } from 'node:fs/promises'
4import path from 'node:path'
5import { fileURLToPath } from 'node:url'
6const root = fileURLToPath(new URL('../', import.meta.url))
7const artifacts = path.join(root, '.artifacts/integration-packages')
8await rm(artifacts, { recursive: true, force: true })
9await mkdir(path.join(artifacts, 'packs'), { recursive: true })
10run(
11 'pnpm',
12 [
13 '--dir',
14 'packages/client',
15 'pack',
16 '--pack-destination',
17 path.join(artifacts, 'packs'),
18 ],
19 root
21const [pack] = (await readdir(path.join(artifacts, 'packs'))).filter((p) =>
22 p.endsWith('.tgz')
24assert(pack)
25for (const kind of ['reference', 'candidate']) {
26 const cwd = path.join(artifacts, kind)
27 await cp(path.join(root, 'examples'), cwd, { recursive: true })
28 await cp(
29 path.join(root, 'tests/compatibility/integrations/resolution.mjs'),
30 path.join(cwd, 'resolution.mjs')
31 )
32 const replacement =
33 kind === 'candidate'
34 ? `file:${path.join(artifacts, 'packs', pack)}`
35 : '1.5.28'
36 await writeFile(
37 path.join(cwd, 'package.json'),
38 JSON.stringify(
39 {
40 name: `integration-${kind}`,
41 private: true,
42 type: 'module',
43 dependencies: {
44 '@electric-sql/client': replacement,
45 '@electric-sql/react': '1.0.57',
46 '@tanstack/electric-db-collection': '0.5.8',
47 '@tanstack/react-db': '0.5.7',
48 react: '19.2.0',
49 'react-dom': '19.2.0',
50 '@types/react': '19.2.2',
51 '@types/react-dom': '19.2.2',
52 typescript: '5.9.3',
53 'typescript-minimum': 'npm:typescript@5.5.4',
54 vite: '7.1.9',
55 'playwright-core': '1.56.1',
56 },
57 pnpm: { overrides: { '@electric-sql/client': replacement } },
58 },
59 null,
60 2
61 )
62 )
63 await writeFile(
64 path.join(cwd, 'tsconfig.json'),
65 JSON.stringify(
66 {
67 compilerOptions: {
68 target: 'ES2022',
69 module: 'ESNext',
70 moduleResolution: 'Bundler',
71 strict: true,
72 skipLibCheck: false,
73 noEmit: true,
74 jsx: 'react-jsx',
75 lib: ['ES2022', 'DOM', 'DOM.Iterable'],
76 types: ['react', 'react-dom'],
77 },
78 include: ['**/*.ts', '**/*.tsx'],
79 exclude: ['node_modules'],
80 },
81 null,
82 2
83 )
84 )
85 run(
86 'pnpm',
87 ['install', '--ignore-workspace', '--ignore-scripts', '--prefer-offline'],
88 cwd
89 )
90 for (const compiler of ['typescript', 'typescript-minimum'])
91 run(
92 process.execPath,
93 [`node_modules/${compiler}/bin/tsc`, '-p', 'tsconfig.json'],
94 cwd
95 )
96 run(process.execPath, ['resolution.mjs'], cwd)
97 run(process.execPath, ['node_modules/vite/bin/vite.js', 'build'], cwd)
99console.log(
100 'Identical basic/React/eager TanStack consumers compile and build against original and packed replacement'
102function run(command, args, cwd) {
103 const result = spawnSync(command, args, {
104 cwd,
105 stdio: 'inherit',
106 env: { ...process.env, CI: 'true' },
107 })
108 if (result.error) throw result.error
109 assert.equal(result.status, 0, `${command} ${args.join(' ')} failed`)