Skip to content

Commit ba929aa

Browse files
committed
Add e2e test
1 parent fb016bf commit ba929aa

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

end2end/tests/express-postgres.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ t.before(() => {
1515
if (stderr && stderr.toString().length > 0) {
1616
throw new Error(`Failed to build: ${stderr.toString()}`);
1717
}
18+
19+
const { stderr2 } = spawnSync("node", ["esbuild-wrong.js"], {
20+
cwd: directory,
21+
});
22+
23+
if (stderr2 && stderr2.toString().length > 0) {
24+
throw new Error(`Failed to build: ${stderr2.toString()}`);
25+
}
1826
});
1927

2028
entrypoints.forEach((entrypoint) => {
@@ -77,6 +85,10 @@ entrypoints.forEach((entrypoint) => {
7785
t.equal(normalSearch.status, 200);
7886
t.match(stdout, /Starting agent/);
7987
t.match(stderr, /Zen has blocked an SQL injection/);
88+
t.notMatch(
89+
stderr,
90+
/Your application seems to be using a bundler without externalizing Zen/
91+
);
8092
}
8193
)
8294
.catch((error) => {
@@ -229,3 +241,34 @@ t.test("it blocks in blocking mode (with dd-trace)", (t) => {
229241
server.kill();
230242
});
231243
});
244+
245+
t.test("it prints warning before crashing if bundled", (t) => {
246+
const server = spawn(`node`, ["compiled-bundled.js", "4003"], {
247+
env: { ...process.env, AIKIDO_DEBUG: "true", AIKIDO_BLOCKING: "true" },
248+
cwd: directory,
249+
});
250+
251+
server.on("close", () => {
252+
t.match(
253+
stderr,
254+
/Your application seems to be using a bundler without externalizing Zen/
255+
);
256+
t.match(stderr, /ENOENT: no such file or directory/); // Can't load wasm
257+
258+
t.end();
259+
});
260+
261+
server.on("error", (err) => {
262+
t.fail(err.message);
263+
});
264+
265+
let stdout = "";
266+
server.stdout.on("data", (data) => {
267+
stdout += data.toString();
268+
});
269+
270+
let stderr = "";
271+
server.stderr.on("data", (data) => {
272+
stderr += data.toString();
273+
});
274+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/compiled.js
2+
/compiled-bundled.js
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { build } = require("esbuild");
2+
3+
build({
4+
entryPoints: ["./app.js"],
5+
bundle: true,
6+
platform: "node",
7+
target: "node18",
8+
outfile: "./compiled-bundled.js",
9+
});

0 commit comments

Comments
 (0)