From c6b94f3d2549ecf35b6c998cfe58672cecedd9c6 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 18 Apr 2020 14:54:05 +0200 Subject: [PATCH] replace fastify with restana for tests --- package.json | 2 +- test.js | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 0549b96..5c8badd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test.js b/test.js index 7a2dfa3..7461c84 100644 --- a/test.js +++ b/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 });