|
| 1 | +import { describe, expect, test } from 'vitest'; |
| 2 | +import { createRequire } from 'node:module'; |
| 3 | + |
| 4 | +const require = createRequire(import.meta.url); |
| 5 | + |
| 6 | +const cjsSubpaths = [ |
| 7 | + 'ep_etherpad-lite/node/eejs', |
| 8 | + 'ep_etherpad-lite/node/db/PadManager', |
| 9 | + 'ep_etherpad-lite/node/db/API.js', |
| 10 | + 'ep_etherpad-lite/node/db/AuthorManager', |
| 11 | + 'ep_etherpad-lite/static/js/pad_utils', |
| 12 | + 'ep_etherpad-lite/tests/backend/common', |
| 13 | +]; |
| 14 | + |
| 15 | +const esmSubpaths = [ |
| 16 | + 'ep_etherpad-lite/node/eejs/index.js', |
| 17 | + 'ep_etherpad-lite/node/db/PadManager.js', |
| 18 | + 'ep_etherpad-lite/node/db/API.js', |
| 19 | + 'ep_etherpad-lite/static/js/pad_utils.js', |
| 20 | +]; |
| 21 | + |
| 22 | +describe('ep_etherpad-lite exports map', () => { |
| 23 | + describe('require() condition (CJS plugins)', () => { |
| 24 | + for (const spec of cjsSubpaths) { |
| 25 | + test(`require('${spec}') resolves`, () => { |
| 26 | + const resolved = require.resolve(spec); |
| 27 | + expect(resolved).toMatch(/\.cjs$/); |
| 28 | + }); |
| 29 | + |
| 30 | + test(`require('${spec}') loads a module`, () => { |
| 31 | + const mod = require(spec); |
| 32 | + expect(mod).toBeTruthy(); |
| 33 | + expect(typeof mod).toBe('object'); |
| 34 | + }); |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + describe('import() condition (ESM plugins)', () => { |
| 39 | + for (const spec of esmSubpaths) { |
| 40 | + test(`import('${spec}') resolves to a .js file`, async () => { |
| 41 | + const mod = await import(spec); |
| 42 | + expect(mod).toBeTruthy(); |
| 43 | + }); |
| 44 | + } |
| 45 | + }); |
| 46 | +}); |
0 commit comments