|
1 | 1 | import { join } from 'node:path';
|
2 |
| -import { type RslibConfig, build } from '@rslib/core'; |
| 2 | +import { build } from '@rslib/core'; |
3 | 3 | import { expect, test } from 'vitest';
|
4 |
| -import { globContentJSON } from '#helper'; |
| 4 | +import { getEntryJsResults } from '#shared'; |
| 5 | +import { loadConfig } from '../../../packages/core/src/config'; |
5 | 6 |
|
6 |
| -test('define', async () => { |
| 7 | +test('define in js', async () => { |
7 | 8 | delete process.env.NODE_ENV;
|
8 | 9 |
|
9 |
| - const rslibConfig: RslibConfig = { |
10 |
| - lib: [ |
11 |
| - { |
12 |
| - format: 'esm', |
13 |
| - output: { |
14 |
| - distPath: { |
15 |
| - root: join(__dirname, './dist/esm'), |
16 |
| - }, |
17 |
| - }, |
18 |
| - }, |
19 |
| - { |
20 |
| - format: 'cjs', |
21 |
| - output: { |
22 |
| - distPath: { |
23 |
| - root: join(__dirname, './dist/cjs'), |
24 |
| - }, |
25 |
| - }, |
26 |
| - }, |
27 |
| - ], |
28 |
| - source: { |
29 |
| - entry: { |
30 |
| - main: join(__dirname, './js/src/index.js'), |
31 |
| - }, |
32 |
| - define: { |
33 |
| - VERSION: JSON.stringify('1.0.0'), |
34 |
| - }, |
35 |
| - }, |
36 |
| - }; |
| 10 | + const fixturePath = join(__dirname, 'js'); |
| 11 | + const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts')); |
| 12 | + await build(rslibConfig); |
| 13 | + const results = await getEntryJsResults(rslibConfig); |
37 | 14 |
|
38 |
| - const instance = await build(rslibConfig); |
| 15 | + expect(results.esm).not.toContain('console.info(VERSION)'); |
| 16 | + expect(results.esm).toContain('1.0.0'); |
| 17 | + expect(results.cjs).not.toContain('console.info(VERSION)'); |
| 18 | + expect(results.cjs).toContain('1.0.0'); |
| 19 | +}); |
| 20 | + |
| 21 | +test('define in ts', async () => { |
| 22 | + delete process.env.NODE_ENV; |
39 | 23 |
|
40 |
| - const results = await globContentJSON(instance[0]!.context.distPath, { |
41 |
| - absolute: true, |
42 |
| - ignore: ['/**/*.map'], |
43 |
| - }); |
| 24 | + const fixturePath = join(__dirname, 'ts'); |
| 25 | + const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts')); |
| 26 | + await build(rslibConfig); |
| 27 | + const results = await getEntryJsResults(rslibConfig); |
44 | 28 |
|
45 |
| - const entryJs = Object.keys(results).find((file) => file.endsWith('.js')); |
46 |
| - expect(results[entryJs!]).not.toContain('console.info(VERSION)'); |
| 29 | + expect(results.esm).not.toContain('console.info(VERSION)'); |
| 30 | + expect(results.esm).toContain('1.0.0'); |
| 31 | + expect(results.cjs).not.toContain('console.info(VERSION)'); |
| 32 | + expect(results.cjs).toContain('1.0.0'); |
47 | 33 | });
|
0 commit comments