Skip to content

Commit

Permalink
Merge pull request #80 from davidmyersdev/77-missing-zlib-imports
Browse files Browse the repository at this point in the history
Make sure all modules under `buffer` are exported
  • Loading branch information
davidmyersdev authored Feb 10, 2024
2 parents b981b7a + c87b6b4 commit 024fea9
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 4 deletions.
19 changes: 18 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 41 additions & 3 deletions shims/buffer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
// eslint-disable-next-line unicorn/prefer-node-protocol, n/no-deprecated-api
import { Buffer, SlowBuffer, kMaxLength } from 'buffer'
import {
Blob,
BlobOptions,
Buffer,
File,
FileOptions,
INSPECT_MAX_BYTES,
// eslint-disable-next-line n/no-deprecated-api
SlowBuffer,
TranscodeEncoding,
atob,
btoa,
constants,
isAscii,
isUtf8,
kMaxLength,
kStringMaxLength,
resolveObjectURL,
transcode,
// eslint-disable-next-line unicorn/prefer-node-protocol
} from 'buffer'

export {
Blob,
BlobOptions,
Buffer,
File,
FileOptions,
INSPECT_MAX_BYTES,
SlowBuffer,
TranscodeEncoding,
atob,
btoa,
constants,
isAscii,
isUtf8,
kMaxLength,
kStringMaxLength,
resolveObjectURL,
transcode,
}

export { Buffer, SlowBuffer, kMaxLength }
export default Buffer
12 changes: 12 additions & 0 deletions test/error-repros/missing-zlib-imports/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>missing-zlib-imports</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/index.ts"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions test/error-repros/missing-zlib-imports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "missing-zlib-imports",
"type": "module",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "vite build",
"dev": "vite",
"test:e2e": "CI=true run-p test:e2e:*",
"test:e2e:build": "VITE_COMMAND=build WEB_SERVER_COMMAND='vite build && vite preview --port 15176' WEB_SERVER_URL='http://localhost:15176' playwright test",
"test:e2e:dev": "VITE_COMMAND=dev WEB_SERVER_COMMAND='vite dev --port 15175' WEB_SERVER_URL='http://localhost:15175' playwright test"
},
"dependencies": {
"fast-zlib": "^2.0.1",
"vite-plugin-node-polyfills": "workspace:*"
},
"devDependencies": {
"vite": "^5.1.1"
}
}
29 changes: 29 additions & 0 deletions test/error-repros/missing-zlib-imports/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { defineConfig, devices } from '@playwright/test'

const webServerCommand = process.env.WEB_SERVER_COMMAND || 'pnpm dev'
const webServerUrl = process.env.WEB_SERVER_URL || 'http://localhost:5173'

// https://playwright.dev/docs/test-configuration
export default defineConfig({
forbidOnly: !!process.env.CI,
fullyParallel: true,
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
reporter: 'html',
retries: process.env.CI ? 2 : 0,
testDir: './test/e2e',
use: {
baseURL: webServerUrl,
trace: 'on-first-retry',
},
webServer: {
command: webServerCommand,
stdout: 'ignore',
url: webServerUrl,
},
workers: process.env.CI ? 1 : undefined,
})
4 changes: 4 additions & 0 deletions test/error-repros/missing-zlib-imports/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import zlib from 'fast-zlib'

// eslint-disable-next-line no-console
console.log(Object.keys(zlib))
27 changes: 27 additions & 0 deletions test/error-repros/missing-zlib-imports/test/e2e/main.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, test } from '@playwright/test'

test('sets the page title', async ({ page }) => {
await page.goto('/')

await expect(page).toHaveTitle('missing-zlib-imports')
})

test('logs the correct values', async ({ page }) => {
const errors = []
const logs = []

page.on('console', (message) => {
logs.push(message.text())
})

page.on('pageerror', (error) => {
errors.push(error.message)
})

await page.goto('/')

expect(errors).toEqual([])
expect(logs).toContainEqual(
'[Inflate, Deflate, InflateRaw, DeflateRaw, Gzip, Gunzip, Unzip, BrotliCompress, BrotliDecompress, constants, default]',
)
})
12 changes: 12 additions & 0 deletions test/error-repros/missing-zlib-imports/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'

// https://vitejs.dev/config/
export default defineConfig({
optimizeDeps: {
force: true,
},
plugins: [
nodePolyfills(),
],
})
7 changes: 7 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: ['**/*.test.ts'],
},
})

0 comments on commit 024fea9

Please sign in to comment.