replace fastify with restana for tests
This commit is contained in:
parent
618b3f6241
commit
c6b94f3d25
@ -35,7 +35,6 @@
|
|||||||
"eslint": "6.8.0",
|
"eslint": "6.8.0",
|
||||||
"eslint-config-silverwind": "11.0.2",
|
"eslint-config-silverwind": "11.0.2",
|
||||||
"execa": "4.0.0",
|
"execa": "4.0.0",
|
||||||
"fastify": "2.13.1",
|
|
||||||
"hosted-git-info": "3.0.4",
|
"hosted-git-info": "3.0.4",
|
||||||
"jest": "25.3.0",
|
"jest": "25.3.0",
|
||||||
"make-fetch-happen": "8.0.4",
|
"make-fetch-happen": "8.0.4",
|
||||||
@ -43,6 +42,7 @@
|
|||||||
"node-fetch": "2.6.0",
|
"node-fetch": "2.6.0",
|
||||||
"rc": "1.2.8",
|
"rc": "1.2.8",
|
||||||
"registry-auth-token": "4.1.1",
|
"registry-auth-token": "4.1.1",
|
||||||
|
"restana": "4.3.2",
|
||||||
"rollup": "2.6.1",
|
"rollup": "2.6.1",
|
||||||
"rollup-plugin-hashbang": "2.2.2",
|
"rollup-plugin-hashbang": "2.2.2",
|
||||||
"rollup-plugin-terser": "5.3.0",
|
"rollup-plugin-terser": "5.3.0",
|
||||||
|
23
test.js
23
test.js
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
const del = require("del");
|
const del = require("del");
|
||||||
const execa = require("execa");
|
const execa = require("execa");
|
||||||
const fastify = require("fastify");
|
const restana = require("restana");
|
||||||
const tempy = require("tempy");
|
const tempy = require("tempy");
|
||||||
const {bin} = require("./package.json");
|
const {bin} = require("./package.json");
|
||||||
const {join} = require("path");
|
const {join} = require("path");
|
||||||
const {test, expect, beforeAll, afterAll} = global;
|
const {test, expect, beforeAll, afterAll} = global;
|
||||||
const {writeFile, readFile} = require("fs").promises;
|
const {writeFile, readFile} = require("fs").promises;
|
||||||
const {promisify} = require("util");
|
const {isIPv6} = require("net");
|
||||||
|
|
||||||
const packageJson = require("./fixtures/test.json");
|
const packageJson = require("./fixtures/test.json");
|
||||||
const testDir = tempy.directory();
|
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;
|
let npmServer, githubServer, githubUrl, npmUrl;
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
let commits, tags;
|
let commits, tags;
|
||||||
|
|
||||||
[npmServer, githubServer, commits, tags] = await Promise.all([
|
[npmServer, githubServer, commits, tags] = await Promise.all([
|
||||||
fastify(),
|
restana(),
|
||||||
fastify(),
|
restana(),
|
||||||
readFile(join(__dirname, "fixtures/github/updates-commits.json")),
|
readFile(join(__dirname, "fixtures/github/updates-commits.json")),
|
||||||
readFile(join(__dirname, "fixtures/github/updates-tags.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/commits", (_, res) => res.send(commits));
|
||||||
githubServer.get("/repos/silverwind/updates/git/refs/tags", (_, res) => res.send(tags));
|
githubServer.get("/repos/silverwind/updates/git/refs/tags", (_, res) => res.send(tags));
|
||||||
|
|
||||||
[githubUrl, npmUrl] = await Promise.all([
|
[githubServer, npmServer] = await Promise.all([
|
||||||
promisify(githubServer.listen).bind(githubServer)(0),
|
githubServer.start(0),
|
||||||
promisify(npmServer.listen).bind(npmServer)(0),
|
npmServer.start(0),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
githubUrl = makeUrl(githubServer);
|
||||||
|
npmUrl = makeUrl(npmServer);
|
||||||
|
|
||||||
await writeFile(join(testDir, ".npmrc"), `registry=${npmUrl}`); // Fake registry
|
await writeFile(join(testDir, ".npmrc"), `registry=${npmUrl}`); // Fake registry
|
||||||
await writeFile(join(testDir, "package.json"), JSON.stringify(packageJson, null, 2)); // Copy fixture
|
await writeFile(join(testDir, "package.json"), JSON.stringify(packageJson, null, 2)); // Copy fixture
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user