-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathindex.spec.js
More file actions
executable file
·194 lines (159 loc) · 5.73 KB
/
Copy pathindex.spec.js
File metadata and controls
executable file
·194 lines (159 loc) · 5.73 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env node
/* eslint-disable no-console */
'use strict'
const assert = require('node:assert/strict')
const chproc = require('node:child_process')
const pathModule = require('node:path')
const fs = require('node:fs')
const { describe, before, it } = require('mocha')
// sub process must be executed inside TEST_DIR
const TEST_DIR = pathModule.join(__dirname, '.')
const execSync = (command, options) => {
console.log(command)
chproc.execSync(command, { ...(options ?? {}), cwd: TEST_DIR })
}
const rmSync = (path, options) => fs.rmSync(pathModule.join(TEST_DIR, path), options)
const readFileSync = (path, options) => fs.readFileSync(pathModule.join(TEST_DIR, path), options)
const originalDir = process.cwd()
const versionsPackageJson = require('../../packages/dd-trace/test/plugins/versions/package.json')
const maximumEsbuildVersion = versionsPackageJson.dependencies.esbuild
// This should switch to our withVersion helper. The order here currently matters.
const { ESBUILD_VERSION } = process.env
const esbuildVersions = ESBUILD_VERSION ? [ESBUILD_VERSION] : ['0.16.12', maximumEsbuildVersion]
const timeout = 1000 * 45
esbuildVersions.forEach((version) => {
describe(`esbuild ${version}`, function () {
this.timeout(timeout)
before(() => {
process.chdir(TEST_DIR)
execSync('npm install', {
timeout,
})
execSync(`npm install esbuild@${version}`, {
timeout,
})
})
after(() => {
process.chdir(originalDir)
execSync('npm remove esbuild', {
timeout,
})
})
it('works', () => {
execSync('npm run build')
try {
execSync('npm run built', {
timeout,
})
} catch (err) {
console.error(err)
process.exit(1)
} finally {
rmSync('./out.js', { force: true })
}
})
it('does not bundle modules listed in .external', () => {
execSync('node ./build-and-test-skip-external.js', {
timeout,
})
})
it('handles typescript apps that import without file extensions', () => {
execSync('node ./build-and-test-typescript.mjs', {
timeout,
})
})
it('handles the complex aws-sdk package with dynamic requires', () => {
execSync('node ./build-and-test-aws-sdk.js', {
timeout,
})
})
it('handles scoped node_modules', () => {
execSync('node ./build-and-test-koa.mjs', {
timeout,
})
})
it('handles instrumentations where the patching function is a property of the hook', () => {
execSync('node ./build-and-test-openai.js', {
timeout,
})
})
it('injects Git metadata into bundled applications', () => {
execSync('node ./build-and-test-git-tags.js', {
timeout,
})
})
it('prints a warning when user opts to minify output without retaining class names', () => {
execSync('node ./build-and-test-minify.js', {
timeout,
})
})
describe('ESM', () => {
afterEach(() => {
rmSync('./out.mjs', { force: true })
rmSync('./out.js', { force: true })
rmSync('./basic-test.mjs', { force: true })
})
it('works', () => {
execSync('npm run build:esm')
execSync('npm run built:esm', {
timeout,
})
})
it('runs minified ESM bundles without ReferenceError on arguments', () => {
execSync('node ./build-and-test-esm-minify.mjs', {
timeout,
})
})
it('keeps __filename, __dirname, and relative requires working in a minified instrumented module', () => {
execSync('node ./build-and-test-esm-minify-globals.mjs', {
timeout,
})
})
it('should not override existing js banner', () => {
execSync('node ./build-and-run.esm-unrelated-js-banner.mjs', {
timeout,
})
const builtFile = readFileSync('./out.mjs').toString()
assert.match(builtFile, /\/\* js test \*\//)
})
it('should contain the definitions when esm is inferred from outfile', () => {
execSync('node ./build-and-run.esm-relying-in-extension.mjs', {
timeout,
})
const builtFile = readFileSync('./out.mjs').toString()
assert.match(builtFile, /globalThis\.__filename \?\?= \$dd_fileURLToPath\(import\.meta\.url\);/)
})
it('should contain the definitions when esm is inferred from format', () => {
execSync('node ./build-and-run.esm-relying-in-format.mjs', {
timeout,
})
const builtFile = readFileSync('./out.mjs').toString()
assert.match(builtFile, /globalThis\.__filename \?\?= \$dd_fileURLToPath\(import\.meta\.url\);/)
})
it('should contain the definitions when format is inferred from out extension', () => {
execSync('node ./build-and-run.esm-relying-in-out-extension.mjs', {
timeout,
})
const builtFile = readFileSync('./basic-test.mjs').toString()
assert.match(builtFile, /globalThis\.__filename \?\?= \$dd_fileURLToPath\(import\.meta\.url\);/)
})
it('should not contain the definitions when no esm is specified', () => {
execSync('node ./build.js', {
timeout,
})
const builtFile = readFileSync('./out.js').toString()
assert.doesNotMatch(builtFile, /globalThis\.__filename \?\?= \$dd_fileURLToPath\(import\.meta\.url\);/)
})
it('should not crash when it is already patched using global', () => {
execSync('node ./build-and-run.esm-patched-global-banner.mjs', {
timeout,
})
})
it('should not crash when it is already patched using const', () => {
execSync('node ./build-and-run.esm-patched-const-banner.mjs', {
timeout,
})
})
})
})
})