Skip to content

Commit

Permalink
test(unit): improve before/after teardown in plugin test
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobridge committed Mar 13, 2024
1 parent fb8dbe7 commit 8e59b9e
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions packages/artillery/test/testcases/plugins/plugins-processor.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { test } = require('tap');
const { test, beforeEach, before, afterEach } = require('tap');
const http = require('http');
const { $ } = require('zx');
const path = require('path');
Expand All @@ -18,10 +18,16 @@ function createServer() {
});
}

(async function () {
const server = createServer().listen(0);
let server;
let overrides;

const overrides = JSON.stringify({
before(async () => {
await $`${A9} -V`;
});

beforeEach(async () => {
server = createServer().listen(0);
overrides = JSON.stringify({
config: {
phases: [{ duration: 2, arrivalRate: 2 }],
target: `http://localhost:${server.address().port}`,
Expand All @@ -31,20 +37,20 @@ function createServer() {
}
}
});

await $`${A9} -V`;

test('plugins can attach functions to processor object', async (t) => {
const output = await $`ARTILLERY_PLUGIN_PATH=${path.join(
__dirname,
'../../plugins'
)} ${A9} run --quiet --overrides ${overrides} ${path.join(
__dirname,
'/script.json'
)}`;

t.match(output, /afterResponse hook/, 'plugin should have been called');

server.close(t.end);
});
})();
});

afterEach(async () => {
server.close();
});

test('plugins can attach functions to processor object', async (t) => {
const output = await $`ARTILLERY_PLUGIN_PATH=${path.join(
__dirname,
'../../plugins'
)} ${A9} run --quiet --overrides ${overrides} ${path.join(
__dirname,
'/script.json'
)}`;

t.match(output, /afterResponse hook/, 'plugin should have been called');
});

0 comments on commit 8e59b9e

Please sign in to comment.