Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Package.json validation tests (#2938)
Browse files Browse the repository at this point in the history
* 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
Teal Larson and grouparoo-bot committed Feb 8, 2022
1 parent 33c4585 commit 05a2498
Show file tree
Hide file tree
Showing 19 changed files with 18,245 additions and 741 deletions.
168 changes: 42 additions & 126 deletions .circleci/config.yml
Expand Up @@ -179,114 +179,6 @@ jobs:
- ui/ui-community/.next
- ui/ui-config/.next
- ui/ui-enterprise/.next
license-checker:
environment:
GROUPAROO_TELEMETRY_ENABLED: "false"
docker:
- image: circleci/node:16.8.0
auth:
username: $DOCKERHUB_USERNAME
password: $DOCKERHUB_PASSWORD
steps:
- checkout
- restore_cache:
<<: *module-other-cache
- restore_cache:
<<: *plugin-1-cache
- restore_cache:
<<: *plugin-2-cache
- restore_cache:
<<: *plugin-3-cache
- restore_cache:
<<: *plugin-4-cache
- restore_cache:
<<: *dist-1-cache
- restore_cache:
<<: *dist-2-cache
- restore_cache:
<<: *dist-3-cache
- restore_cache:
<<: *dist-4-cache
- restore_cache:
<<: *core-cache
- run:
name: install pnpm
command: sudo npm install -g pnpm
- run:
name: license-checker
command: ./tools/license-checker/check
spell-checker:
environment:
GROUPAROO_TELEMETRY_ENABLED: "false"
docker:
- image: circleci/node:16.8.0
auth:
username: $DOCKERHUB_USERNAME
password: $DOCKERHUB_PASSWORD
steps:
- checkout
- restore_cache:
<<: *module-other-cache
- restore_cache:
<<: *plugin-1-cache
- restore_cache:
<<: *plugin-2-cache
- restore_cache:
<<: *plugin-3-cache
- restore_cache:
<<: *plugin-4-cache
- restore_cache:
<<: *dist-1-cache
- restore_cache:
<<: *dist-2-cache
- restore_cache:
<<: *dist-3-cache
- restore_cache:
<<: *dist-4-cache
- restore_cache:
<<: *core-cache
- run:
name: install pnpm
command: sudo npm install -g pnpm
- run:
name: spell-checker
command: ./tools/spell-checker/check
version-checker:
environment:
GROUPAROO_TELEMETRY_ENABLED: "false"
docker:
- image: circleci/node:16.8.0
auth:
username: $DOCKERHUB_USERNAME
password: $DOCKERHUB_PASSWORD
steps:
- checkout
- restore_cache:
<<: *module-other-cache
- restore_cache:
<<: *plugin-1-cache
- restore_cache:
<<: *plugin-2-cache
- restore_cache:
<<: *plugin-3-cache
- restore_cache:
<<: *plugin-4-cache
- restore_cache:
<<: *dist-1-cache
- restore_cache:
<<: *dist-2-cache
- restore_cache:
<<: *dist-3-cache
- restore_cache:
<<: *dist-4-cache
- restore_cache:
<<: *core-cache
- run:
name: install pnpm
command: sudo npm install -g pnpm
- run:
name: version-checker
command: ./tools/version-checker/check
linter:
environment:
GROUPAROO_TELEMETRY_ENABLED: "false"
Expand Down Expand Up @@ -873,6 +765,42 @@ jobs:
- run:
name: test
command: cd core && ./node_modules/.bin/jest __tests__/tasks --ci --maxWorkers 2
test-root:
environment:
GROUPAROO_TELEMETRY_ENABLED: "false"
docker:
- image: circleci/node:16.8.0
auth:
username: $DOCKERHUB_USERNAME
password: $DOCKERHUB_PASSWORD
steps:
- checkout
- restore_cache:
<<: *module-other-cache
- restore_cache:
<<: *plugin-1-cache
- restore_cache:
<<: *plugin-2-cache
- restore_cache:
<<: *plugin-3-cache
- restore_cache:
<<: *plugin-4-cache
- restore_cache:
<<: *dist-1-cache
- restore_cache:
<<: *dist-2-cache
- restore_cache:
<<: *dist-3-cache
- restore_cache:
<<: *dist-4-cache
- restore_cache:
<<: *core-cache
- run:
name: update apt
command: sudo apt update
- run:
name: test-root
command: cd . && ./node_modules/.bin/jest ./__tests__/packages --ci --maxWorkers 2 --passWithNoTests
test-core-local-models:
environment:
GROUPAROO_TELEMETRY_ENABLED: "false"
Expand Down Expand Up @@ -3753,21 +3681,6 @@ workflows:
- build:
filters:
<<: *ignored-branches
- license-checker:
filters:
<<: *ignored-branches
requires:
- build
- spell-checker:
filters:
<<: *ignored-branches
requires:
- build
- version-checker:
filters:
<<: *ignored-branches
requires:
- build
- linter:
filters:
<<: *ignored-branches
Expand Down Expand Up @@ -3823,6 +3736,11 @@ workflows:
<<: *ignored-branches
requires:
- build
- test-root:
filters:
<<: *ignored-branches
requires:
- build
- test-core-local-models:
filters:
<<: *ignored-branches
Expand Down Expand Up @@ -4087,9 +4005,6 @@ workflows:
filters:
<<: *ignored-branches
requires:
- license-checker
- spell-checker
- version-checker
- linter
- test-core-actions
- test-core-bin
Expand All @@ -4101,6 +4016,7 @@ workflows:
- test-core-notifiers
- test-core-snapshots
- test-core-tasks
- test-root
- test-core-local-models
- test-core-local-actions
- test-core-local-tasks
Expand Down
118 changes: 118 additions & 0 deletions __tests__/packages.ts
@@ -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);
}
);
});
});

0 comments on commit 05a2498

Please sign in to comment.