add a non-json test

This commit is contained in:
silverwind 2020-07-15 00:01:04 +02:00
parent 0635c40230
commit fb12aa1a1a
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
2 changed files with 20 additions and 6 deletions

@ -37,6 +37,7 @@
"execa": "4.0.3",
"hosted-git-info": "3.0.5",
"jest": "26.1.0",
"jest-extended": "0.11.5",
"make-fetch-happen": "8.0.8",
"minimist": "1.2.5",
"node-fetch": "2.6.0",
@ -53,6 +54,9 @@
},
"jest": {
"verbose": false,
"testTimeout": 10000
"testTimeout": 10000,
"setupFilesAfterEnv": [
"jest-extended"
]
}
}

20
test.js

@ -10,8 +10,10 @@ const {test, expect, beforeAll, afterAll} = global;
const {writeFile, readFile} = require("fs").promises;
const {isIPv6} = require("net");
const packageJson = require("./fixtures/test.json");
const testFile = "./fixtures/test.json";
const testPkg = require(testFile);
const testDir = tempy.directory();
const script = join(__dirname, bin);
const dependencyTypes = [
"dependencies",
@ -22,7 +24,7 @@ const dependencyTypes = [
const testPackages = new Set();
for (const dependencyType of dependencyTypes) {
for (const name of Object.keys(packageJson[dependencyType] || [])) {
for (const name of Object.keys(testPkg[dependencyType] || [])) {
testPackages.add(name);
}
}
@ -62,7 +64,7 @@ beforeAll(async () => {
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
await writeFile(join(testDir, "package.json"), JSON.stringify(testPkg, null, 2)); // Copy fixture
});
afterAll(async () => {
@ -75,8 +77,8 @@ afterAll(async () => {
function makeTest(args, expected) {
return async () => {
const argsArr = [...args.split(/\s+/), "-G", githubUrl];
const {stdout} = await execa(join(__dirname, bin), argsArr, {cwd: testDir});
const argsArr = [...args.split(/\s+/), "-c", "-G", githubUrl];
const {stdout} = await execa(script, argsArr, {cwd: testDir});
const {results} = JSON.parse(stdout);
// Parse results, with custom validation for the dynamic "age" property
@ -96,6 +98,14 @@ function makeTest(args, expected) {
};
}
test("simple", async () => {
const {stdout, stderr, exitCode} = await execa(script, ["-C", "-f", testFile]);
expect(stderr).toEqual("");
expect(stdout).toInclude("prismjs");
expect(stdout).toInclude("https://github.com/silverwind/updates");
expect(exitCode).toEqual(0);
});
test("latest", makeTest("-j", {
dependencies: {
"gulp-sourcemaps": {