Skip to content

Commit

Permalink
Merge pull request #38 from fisker/fake-registry
Browse files Browse the repository at this point in the history
test: setup a fake registry
  • Loading branch information
silverwind authored Mar 8, 2020
2 parents 7cde5da + 7947bfb commit 5d39d8b
Show file tree
Hide file tree
Showing 10 changed files with 57,610 additions and 2 deletions.
5,941 changes: 5,941 additions & 0 deletions info/@babel%2fpreset-env.json

Large diffs are not rendered by default.

4,553 changes: 4,553 additions & 0 deletions info/gulp-sourcemaps.json

Large diffs are not rendered by default.

6,569 changes: 6,569 additions & 0 deletions info/html-webpack-plugin.json

Large diffs are not rendered by default.

711 changes: 711 additions & 0 deletions info/jpeg-buffer-orientation.json

Large diffs are not rendered by default.

1,459 changes: 1,459 additions & 0 deletions info/noty.json

Large diffs are not rendered by default.

1,636 changes: 1,636 additions & 0 deletions info/prismjs.json

Large diffs are not rendered by default.

35,988 changes: 35,988 additions & 0 deletions info/styled-components.json

Large diffs are not rendered by default.

688 changes: 688 additions & 0 deletions info/svgstore.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
"text-table": "0.2.0"
},
"devDependencies": {
"create-test-server": "3.0.1",
"del": "5.1.0",
"eslint": "6.7.2",
"eslint-config-silverwind": "5.0.3",
"execa": "3.4.0",
"tempy": "0.3.0",
"versions": "7.0.4"
}
}
64 changes: 62 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,80 @@
const assert = require("assert");
const process = require("process");
const execa = require("execa");
const createTestServer = require("create-test-server");
const tempy = require("tempy");
const fs = require("fs");
const path = require("path");
const del = require("del");

function exit(err) {
const testDir = tempy.directory();

let server;

async function clean() {
await del(testDir, {force: true});
if (server) {
await server.close();
}
}

async function setup() {
server = await createTestServer();

// Server response
for (const packageName of [
"gulp-sourcemaps",
"prismjs",
"svgstore",
"html-webpack-plugin",
"noty",
"jpeg-buffer-orientation",
"styled-components",
"@babel/preset-env",
]) {
const name = packageName.replace(/\//g, "%2f");
const text = fs.readFileSync(path.join(__dirname, "info", `${name}.json`), "utf8");

server.get(
`/${name}`,
text
);
}

const {sslUrl: registry} = server;

// Fake registry
fs.writeFileSync(path.join(testDir, ".npmrc"), `registry=${registry}`);

// Copy fixture
fs.writeFileSync(
path.join(testDir, "test.json"),
fs.readFileSync("test.json")
);
}

async function exit(err) {
await clean();
if (err) {
console.info(err);
}
process.exit(err ? 1 : 0);
}

async function run(args) {
const {stdout} = await execa("./updates.js", args.split(/\s+/));
const {stdout} = await execa(
path.join(process.cwd(), "./updates.js"),
args.split(/\s+/),
{
cwd: testDir
}
);
return JSON.parse(stdout);
}

async function main() {
await setup();

assert.deepStrictEqual(await run("-j -f test.json"), {
results: {
dependencies: {
Expand Down

0 comments on commit 5d39d8b

Please sign in to comment.