Skip to content

Commit

Permalink
feat(init): add reference to mono schema (#2162)
Browse files Browse the repository at this point in the history
* Deliver a big schema as artifact. This will include the core schema as well as schemas from all known plugins. It is delivered here: https://unpkg.com/@stryker-mutator/core/schema/stryker-schema.json
* Add a `$schema` reference to the "mono-schema". A schema file that contains all valid config from all main-supported stryker plugins. This will allow users to explore the different options of our plugin.
  • Loading branch information
nicojs committed May 13, 2020
1 parent a2d3e8b commit 61953c7
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ package-lock.json
.DS_Store
tsconfig.*.tsbuildinfo
src-generated
packages/core/schema
__filterSpecs.js
45 changes: 41 additions & 4 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"@babel/preset-env": "~7.8.3",
"@types/node": "^10.12.18",
"@types/semver": "~6.2.0",
"ajv": "^6.12.2",
"axios": "^0.19.2",
"chai": "~4.2.0",
"chai-as-promised": "~7.1.1",
"cross-env": "~5.2.0",
Expand Down
2 changes: 1 addition & 1 deletion e2e/tasks/run-e2e-tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs = require('fs');
import * as path from 'path';
import * as execa from 'execa';
import execa from 'execa';
import * as semver from 'semver';
import * as os from 'os';
import { from, defer } from 'rxjs';
Expand Down
7 changes: 7 additions & 0 deletions e2e/test/mono-schema/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "mono-schema",
"description": "A test for the 'mono-schema'. A json schema that got merged from all the objects and put into @stryker-mutator/core/schema",
"scripts": {
"test": "mocha --require \"ts-node/register\" verify/verify.ts"
}
}
27 changes: 27 additions & 0 deletions e2e/test/mono-schema/test/invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "../../../node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"allowConsoleColors": true,
"babel": {
"options": {
"compact": "invalid"
}
},
"jest": {
"config": ""
},
"wct": {
"configFile": {}
},
"jasmineConfigFile": false,
"webpack": {
"configFile": []
},
"karma": {
"ngConfig": {
"testArguments": "--test test"
}
},
"tsconfig": {
"moduleResolution": "invalid"
}
}
27 changes: 27 additions & 0 deletions e2e/test/mono-schema/test/valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "../../../node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"allowConsoleColors": true,
"babel": {
"options": {
"compact": "auto"
}
},
"jest": {
"config": {}
},
"wct": {
"configFile": "a file"
},
"jasmineConfigFile": "A file",
"webpack": {
"configFile": "webpack.config.js"
},
"karma": {
"ngConfig": {
"testArguments": { "test": "test" }
}
},
"tsconfig": {
"moduleResolution": "node"
}
}
119 changes: 119 additions & 0 deletions e2e/test/mono-schema/verify/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { expect } from 'chai';
import valid from '../test/valid.json';
import invalid from '../test/invalid.json';
import monoSchema from '@stryker-mutator/core/schema/stryker-schema.json';
import Ajv from 'ajv';
import Axios from 'axios';
import { beforeEach } from 'mocha';

const ajv = new Ajv({
async: true,
allErrors: true,
loadSchema: async (url) => {
const content = await Axios.get(url);
delete content.data.$schema;
return content.data;
},
});

describe('The Stryker meta schema', () => {
let validator: Ajv.ValidateFunction;

beforeEach(async () => {
validator = await ajv.compileAsync(monoSchema);
});

it('should validate a valid schema', async () => {
expect(validator(valid), ajv.errorsText(validator.errors)).true;
});

it('should invalidate a invalid schema', async () => {
expect(validator(invalid)).false;
expect(validator.errors).deep.eq(expectedErrors);
});

const expectedErrors = [
{
keyword: 'enum',
dataPath: '.babel.options.compact',
schemaPath: 'http://json.schemastore.org/babelrc/properties/compact/enum',
params: {
allowedValues: ['auto', true, false],
},
message: 'should be equal to one of the allowed values',
},
{
keyword: 'type',
dataPath: '.jasmineConfigFile',
schemaPath: '#/properties/jasmineConfigFile/type',
params: {
type: 'string',
},
message: 'should be string',
},
{
keyword: 'type',
dataPath: '.jest.config',
schemaPath: '#/properties/jest/properties/config/type',
params: {
type: 'object',
},
message: 'should be object',
},
{
keyword: 'type',
dataPath: '.karma.ngConfig.testArguments',
schemaPath: '#/definitions/karmaNgConfigOptions/properties/testArguments/type',
params: {
type: 'object',
},
message: 'should be object',
},
{
keyword: 'enum',
dataPath: '.tsconfig.moduleResolution',
schemaPath:
'http://json.schemastore.org/tsconfig#/definitions/compilerOptionsDefinition/properties/compilerOptions/properties/moduleResolution/anyOf/0/enum',
params: {
allowedValues: ['Classic', 'Node'],
},
message: 'should be equal to one of the allowed values',
},
{
keyword: 'pattern',
dataPath: '.tsconfig.moduleResolution',
schemaPath:
'http://json.schemastore.org/tsconfig#/definitions/compilerOptionsDefinition/properties/compilerOptions/properties/moduleResolution/anyOf/1/pattern',
params: {
pattern: '^(([Nn]ode)|([Cc]lassic))$',
},
message: 'should match pattern "^(([Nn]ode)|([Cc]lassic))$"',
},
{
keyword: 'anyOf',
dataPath: '.tsconfig.moduleResolution',
schemaPath:
'http://json.schemastore.org/tsconfig#/definitions/compilerOptionsDefinition/properties/compilerOptions/properties/moduleResolution/anyOf',
params: {},
message: 'should match some schema in anyOf',
},
{
keyword: 'type',
dataPath: '.wct.configFile',
schemaPath: '#/properties/wct/properties/configFile/type',
params: {
type: 'string',
},
message: 'should be string',
},
{
keyword: 'type',
dataPath: '.webpack.configFile',
schemaPath: '#/properties/webpack/properties/configFile/type',
params: {
type: 'string',
},
message: 'should be string',
},
];
});
1 change: 1 addition & 0 deletions e2e/test/plugin-options-validation/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "plugin-options-validation",
"scripts": {
"pretest": "rimraf stryker.log",
"test": "stryker run --fileLogLevel info stryker-error-in-plugin-options.conf.json || exit 0",
Expand Down
2 changes: 1 addition & 1 deletion e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "../tsconfig.settings.json",
"compilerOptions": {
"composite": false,
"declaration": false,
"importHelpers": false,
"esModuleInterop": true,
"rootDir": ".",
"types": [
"mocha",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"lint:log": "eslint . --ext .ts,.tsx -f compact -o lint.log",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"clean": "rimraf \"packages/api/!(stryker.conf)+(.d.ts|.js|.map)\" \"packages/*/+(test|src)/**/*+(.d.ts|.js|.map)\" \"packages/*/{.nyc_output,reports,coverage,src-generated,*.tsbuildinfo,.stryker-tmp}\"",
"generate": "node tasks/generate-json-schema-to-ts.js",
"clean": "rimraf \"packages/api/!(stryker.conf)+(.d.ts|.js|.map)\" \"packages/*/+(test|src)/**/*+(.d.ts|.js|.map)\" \"packages/*/{.nyc_output,reports,coverage,src-generated,*.tsbuildinfo}\"",
"generate": "node tasks/generate-json-schema-to-ts.js && node tasks/generate-mono-schema.js",
"prebuild": "npm run generate",
"build": "tsc -b && lerna run build",
"test": "npm run mocha",
Expand Down
1 change: 1 addition & 0 deletions packages/core/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
!src/**
src/**/*.map
src/**/*.ts
!schema/*.json
!src/**/*.d.ts
!readme.md
!LICENSE
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/initializer/StrykerConfigWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class StrykerConfigWriter {
private async writeJsonConfig(commentedConfig: Partial<StrykerOptions>) {
this.out(`Writing & formatting ${STRYKER_JSON_CONFIG_FILE}...`);
const typedConfig = {
$schema: 'https://raw.githubusercontent.com/stryker-mutator/stryker/master/packages/api/schema/stryker-core.json',
$schema: 'https://unpkg.com/@stryker-mutator/core/schema/stryker-schema.json',
...commentedConfig,
};
const formattedConfig = this.stringify(typedConfig);
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/schema/typescript-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"tsconfig": {
"description": "Override tsconfig from your tsconfig.json file",
"type": "object",
"$ref": "http://json.schemastore.org/tsconfig"
"$ref": "http://json.schemastore.org/tsconfig#/definitions/compilerOptionsDefinition/properties/compilerOptions"
}
}
}
Loading

0 comments on commit 61953c7

Please sign in to comment.