-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.test.ts
More file actions
39 lines (36 loc) · 1.11 KB
/
webpack.test.ts
File metadata and controls
39 lines (36 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { mkdtemp, readFile, rm } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import { expect, onTestFinished, test } from 'vitest'
import webpack from 'webpack'
import UnpluginReplace from '../src/webpack.ts'
test('webpack', async () => {
const tmp = await mkdtemp(path.join(os.tmpdir(), 'unplugin-replace-'))
onTestFinished(() => rm(tmp, { recursive: true, force: true }))
await new Promise<webpack.Stats>((resolve, reject) => {
const compiler = webpack({
entry: path.resolve(import.meta.dirname, 'fixtures/main.js'),
output: {
path: tmp,
},
plugins: [
UnpluginReplace({
'process.platform': '"darwin"',
}),
],
mode: 'production',
target: 'node',
optimization: {
minimize: false,
},
})
compiler!.run((error, stats) => {
if (error) return reject(error)
resolve(stats!)
})
})
const result = await readFile(path.resolve(tmp, 'main.js'), 'utf8')
expect(result).toMatchSnapshot()
expect(result).not.contains('process.platform')
expect(result).contains('"darwin"')
})