Open History to see the last commit
1// @vitest-environment node
2import { fileURLToPath } from 'node:url'
3import { build } from 'esbuild'
4import { describe, expect, it } from 'vitest'
5
6// Development warnings must cost nothing in production. An app's bundler
7// replaces `process.env.NODE_ENV` with `"production"` and drops code behind a
8// condition that is then always false. A gate that only a runtime call
9// decides keeps the warning code in every production bundle, even though it
10// never runs. This bundles the adapter as an app's production build would and
11// checks that no warning text survives.
12describe(`react-db production bundle`, () => {
13 it(`contains no development warning code`, async () => {
14 const result = await build({
15 entryPoints: [fileURLToPath(new URL(`../src/index.ts`, import.meta.url))],
16 bundle: true,
17 minify: true,
18 write: false,
19 format: `esm`,
20 platform: `browser`,
21 packages: `external`,
22 // The repo's tsconfig paths would inline workspace packages.
23 tsconfigRaw: `{}`,
24 logLevel: `error`,
25 define: { 'process.env.NODE_ENV': `"production"` },
26 })
27 const code = result.outputFiles[0]!.text
28 // The gate's own call stays, so its environment variable names may
29 // remain; the warnings' bodies and messages may not.
30 for (const text of [
31 `Deriving live query identity from structured`,
32 `This query cannot derive a stable identity`,
33 `Passing a collection with syncMode`,
34 ]) {
35 expect(code.includes(text), text).toBe(false)
36 }
37 })
38})