-
-
Notifications
You must be signed in to change notification settings - Fork 932
ESM build #6254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ESM build #6254
Changes from 17 commits
82beef4
e3a7755
63c12a0
0336d73
e9e573f
22a073c
bbb18d6
265daf6
5bdcb4e
ad9077e
0c1f6be
9b181a1
71af865
5e108f3
2b730cb
92b2b85
48c11d3
9ad23a8
f349838
b739a96
4902b64
3a4e14f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import {describe, test, expect} from 'vitest'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
|
|
||
| describe('ESM build', () => { | ||
| test('ESM main bundle exists and exports expected API', () => { | ||
| const esmPath = path.join(process.cwd(), 'dist/maplibre-gl-dev.mjs'); | ||
| expect(fs.existsSync(esmPath)).toBe(true); | ||
|
|
||
| const content = fs.readFileSync(esmPath, 'utf8'); | ||
|
|
||
| // Check for ES module exports at the end of the file | ||
| expect(content).toMatch(/export\s+\{[^}]+\};\s*$/m); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not super thrilled with checking the string content of the file, is there a better way to check this? |
||
| expect(content).toContain('Map'); | ||
| expect(content).toContain('Marker'); | ||
| expect(content).toContain('Popup'); | ||
| expect(content).toContain('setWorkerUrl'); | ||
| expect(content).toContain('getWorkerUrl'); | ||
|
|
||
| // The bundle should use ES module format (export statements) | ||
| // Note: Some dependencies may contain module.exports internally, | ||
| // but the bundle itself should export using ES module syntax | ||
| expect(content).toMatch(/^export\s+\{/m); | ||
| }); | ||
|
|
||
| test('ESM worker bundle exists', () => { | ||
| const workerPath = path.join(process.cwd(), 'dist/maplibre-gl-worker-dev.mjs'); | ||
| expect(fs.existsSync(workerPath)).toBe(true); | ||
|
|
||
| const content = fs.readFileSync(workerPath, 'utf8'); | ||
|
|
||
| // Worker should be an ES module | ||
| // The worker doesn't export anything but should not use AMD | ||
| expect(content).not.toContain('define.amd'); | ||
|
|
||
| // Should contain worker-specific code | ||
| expect(content).toContain('Actor'); | ||
| }); | ||
|
|
||
| test('Production ESM builds exist', () => { | ||
| // These might not exist if only dev build was run | ||
| const mainProd = path.join(process.cwd(), 'dist/maplibre-gl.mjs'); | ||
| const workerProd = path.join(process.cwd(), 'dist/maplibre-gl-worker.mjs'); | ||
|
|
||
| if (fs.existsSync(mainProd)) { | ||
| const content = fs.readFileSync(mainProd, 'utf8'); | ||
| expect(content).toContain('export {'); | ||
|
Check failure on line 47 in test/build/esm.test.ts
|
||
| } | ||
|
|
||
| if (fs.existsSync(workerProd)) { | ||
| const content = fs.readFileSync(workerProd, 'utf8'); | ||
| // Should be ES module format with export statement | ||
| expect(content).toContain('export'); | ||
| } | ||
| }); | ||
|
|
||
| test('CSP ESM builds follow same pattern', () => { | ||
| const cspMain = path.join(process.cwd(), 'dist/maplibre-gl-csp-dev.mjs'); | ||
| const cspWorker = path.join(process.cwd(), 'dist/maplibre-gl-csp-worker-dev.mjs'); | ||
|
|
||
| if (fs.existsSync(cspMain)) { | ||
| const content = fs.readFileSync(cspMain, 'utf8'); | ||
| expect(content).toContain('export {'); | ||
| // Should be ES module format with export statement | ||
| expect(content).toContain('export'); | ||
| } | ||
|
|
||
| if (fs.existsSync(cspWorker)) { | ||
| const content = fs.readFileSync(cspWorker, 'utf8'); | ||
| // Should be ES module format with export statement | ||
| expect(content).toContain('export'); | ||
| } | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.