replace fastify with restana for tests

This commit is contained in:
silverwind 2020-04-18 14:54:05 +02:00
parent 618b3f6241
commit c6b94f3d25
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
2 changed files with 17 additions and 8 deletions

@ -35,7 +35,6 @@
"eslint": "6.8.0",
"eslint-config-silverwind": "11.0.2",
"execa": "4.0.0",
"fastify": "2.13.1",
"hosted-git-info": "3.0.4",
"jest": "25.3.0",
"make-fetch-happen": "8.0.4",
@ -43,6 +42,7 @@
"node-fetch": "2.6.0",
"rc": "1.2.8",
"registry-auth-token": "4.1.1",
"restana": "4.3.2",
"rollup": "2.6.1",
"rollup-plugin-hashbang": "2.2.2",
"rollup-plugin-terser": "5.3.0",

23
test.js

@ -2,13 +2,13 @@
const del = require("del");
const execa = require("execa");
const fastify = require("fastify");
const restana = require("restana");
const tempy = require("tempy");
const {bin} = require("./package.json");
const {join} = require("path");
const {test, expect, beforeAll, afterAll} = global;
const {writeFile, readFile} = require("fs").promises;
const {promisify} = require("util");
const {isIPv6} = require("net");
const packageJson = require("./fixtures/test.json");
const testDir = tempy.directory();
@ -27,13 +27,19 @@ for (const dependencyType of dependencyTypes) {
}
}
function makeUrl(server) {
const {address, port} = server.address();
const hostname = isIPv6(address) ? `[${address}]` : address;
return Object.assign(new URL("http://x"), {hostname, port}).toString();
}
let npmServer, githubServer, githubUrl, npmUrl;
beforeAll(async () => {
let commits, tags;
[npmServer, githubServer, commits, tags] = await Promise.all([
fastify(),
fastify(),
restana(),
restana(),
readFile(join(__dirname, "fixtures/github/updates-commits.json")),
readFile(join(__dirname, "fixtures/github/updates-tags.json"))
]);
@ -47,11 +53,14 @@ beforeAll(async () => {
githubServer.get("/repos/silverwind/updates/commits", (_, res) => res.send(commits));
githubServer.get("/repos/silverwind/updates/git/refs/tags", (_, res) => res.send(tags));
[githubUrl, npmUrl] = await Promise.all([
promisify(githubServer.listen).bind(githubServer)(0),
promisify(npmServer.listen).bind(npmServer)(0),
[githubServer, npmServer] = await Promise.all([
githubServer.start(0),
npmServer.start(0),
]);
githubUrl = makeUrl(githubServer);
npmUrl = makeUrl(npmServer);
await writeFile(join(testDir, ".npmrc"), `registry=${npmUrl}`); // Fake registry
await writeFile(join(testDir, "package.json"), JSON.stringify(packageJson, null, 2)); // Copy fixture
});