This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Package.json validation tests (#2938)
* initial commit * package json schema changes * pnpm things * tests completed, scripts moved/erased * more moving things * ci configurations * remove moved scripts * fix ci job template * node engine schema pattern * cleanup * Updating things automatically Co-authored-by: Grouparoo Bot <hello@grouparoo.com>
- Loading branch information
1 parent
33c4585
commit 05a2498
Showing
19 changed files
with
18,245 additions
and
741 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { matchersWithOptions } from "jest-json-schema"; | ||
import glob from "glob"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { allPackageFiles } from "../tools/shared/packages"; | ||
import childProcess from "child_process"; | ||
|
||
describe("monorepo content validation", () => { | ||
test("the monorepo does not contain banned words", async () => { | ||
const checkBannedWords = await new Promise<void>((res, reject) => { | ||
childProcess.exec( | ||
"./wordCheck", | ||
{ cwd: path.resolve(__dirname) }, | ||
(error, _stuff, stderr) => { | ||
if (error || stderr) { | ||
return reject(error || stderr); | ||
} | ||
return res(); | ||
} | ||
); | ||
}); | ||
expect(checkBannedWords).resolves; | ||
}); | ||
}); | ||
|
||
describe("package.json validation", () => { | ||
const packageFiles: string[] = allPackageFiles(glob); | ||
const genericSchema = require("./schemaGeneric.json"); | ||
const publicSchema = require("./schemaPublic.json"); | ||
const restrictedSchema = require("./schemaRestricted"); | ||
|
||
expect.extend( | ||
matchersWithOptions({ | ||
schemas: [genericSchema, publicSchema, restrictedSchema], | ||
}) | ||
); | ||
|
||
//used for license checker, but should be generated ahead of time with a fully populated list | ||
const excludedPackages = [ | ||
"@newrelic/aws-sdk@1.1.3", | ||
"@newrelic/koa@3.0.0", | ||
"@newrelic/native-metrics@5.1.0", | ||
"@newrelic/native-metrics@5.2.0", | ||
"@newrelic/superagent@2.0.1", | ||
"emitter-component@1.1.1", | ||
"facebook-nodejs-business-sdk@12.0.1", | ||
]; | ||
|
||
packageFiles.forEach((pkgFile) => { | ||
const pkgJson = JSON.parse(fs.readFileSync(pkgFile, "utf-8")); | ||
const nameAndVersion = `${pkgJson.name}@${pkgJson.version}`; | ||
excludedPackages.push(nameAndVersion); | ||
}); | ||
|
||
describe.each(packageFiles)(`%s`, (pkgFile) => { | ||
const pkgJson = JSON.parse(fs.readFileSync(pkgFile, "utf-8")); | ||
test("it follows Grouparoo's package json schema rules", () => { | ||
/** | ||
* Schema checks: | ||
* - That Author, name, description, version, license, and private exist | ||
* - No dependencies contain a version number with a ~ or ^ | ||
* - Values match expected types | ||
*/ | ||
const schema = | ||
pkgFile.includes("apps") || | ||
pkgFile.includes("tools") || | ||
pkgJson.name === "@grouparoo/grouparoo" | ||
? genericSchema | ||
: pkgJson.name === "@grouparoo/ui-enterprise" | ||
? restrictedSchema | ||
: publicSchema; | ||
|
||
expect(pkgJson).toMatchSchema(schema); | ||
}); | ||
|
||
test("Dependencies use a permitted license", (done) => { | ||
const allowedLicenses = [ | ||
"MPL-2.0", | ||
"MIT", | ||
"Artistic-2.0", | ||
"Apache", | ||
"ISC", | ||
"BSD", | ||
"BSD*", | ||
"BSD-3-Clause", | ||
"BSD-2-Clause", | ||
"CC0-1.0", | ||
"CC-BY-3.0", | ||
"CC-BY-4.0", | ||
"Unlicense", | ||
"WTFPL", | ||
]; | ||
|
||
childProcess.exec( | ||
`./node_modules/.bin/license-checker --excludePackages '${excludedPackages.join( | ||
";" | ||
)}' --start '${path.dirname( | ||
pkgFile | ||
)}' --onlyAllow '${allowedLicenses.join(";")}'`, | ||
{ cwd: path.resolve(__dirname + "/../") }, | ||
|
||
(err, stdout, stderr) => { | ||
done(stderr); | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
test("packages match across the monorepo", (done) => { | ||
childProcess.exec( | ||
`./node_modules/.bin/syncpack list-mismatches`, | ||
{ cwd: path.resolve(__dirname + "/../") }, | ||
(err, stdout) => { | ||
done(stdout); | ||
} | ||
); | ||
}); | ||
}); |
Oops, something went wrong.