Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: serve a JSON schema from website #14792

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/website/build
/website/backers.json
/website/node_modules
/website/static/schemas/
/website/yarn.lock
/website/i18n/*

Expand Down
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
YARN_ENABLE_GLOBAL_CACHE = "true"
YARN_GLOBAL_FOLDER = "/opt/buildhome/.yarn_cache"
YARN_CACHE_FOLDER = "/opt/buildhome/.yarn_cache"
YARN_VERSION = "3.6.4"
YARN_VERSION = "3.7.0"

[context.production]
# Do not build the site if there's no site-related changes
Expand Down
262 changes: 139 additions & 123 deletions packages/jest-schemas/src/raw-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,129 +226,145 @@ const RawHasteConfig = Type.Partial(
);

export const RawInitialOptions = Type.Partial(
Type.Object({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore whitespace (https://github.com/jestjs/jest/pull/14792/files?w=1) - I just added some meta properties at the end

automock: Type.Boolean(),
bail: Type.Union([Type.Boolean(), Type.Number()]),
cache: Type.Boolean(),
cacheDirectory: Type.String(),
ci: Type.Boolean(),
clearMocks: Type.Boolean(),
changedFilesWithAncestor: Type.Boolean(),
changedSince: Type.String(),
collectCoverage: Type.Boolean(),
collectCoverageFrom: Type.Array(Type.String()),
coverageDirectory: Type.String(),
coveragePathIgnorePatterns: Type.Array(Type.String()),
coverageProvider: RawCoverageProvider,
coverageReporters: RawCoverageReporters,
coverageThreshold: RawCoverageThreshold,
dependencyExtractor: Type.String(),
detectLeaks: Type.Boolean(),
detectOpenHandles: Type.Boolean(),
displayName: Type.Union([Type.String(), RawDisplayName]),
expand: Type.Boolean(),
extensionsToTreatAsEsm: Type.Array(Type.String()),
fakeTimers: RawFakeTimers,
filter: Type.String(),
findRelatedTests: Type.Boolean(),
forceCoverageMatch: Type.Array(Type.String()),
forceExit: Type.Boolean(),
json: Type.Boolean(),
globals: Type.Record(Type.String(), Type.Unknown()),
globalSetup: Type.Union([Type.String(), Type.Null()]),
globalTeardown: Type.Union([Type.String(), Type.Null()]),
haste: RawHasteConfig,
id: Type.String(),
injectGlobals: Type.Boolean(),
reporters: Type.Array(
Type.Union([
Type.Object(
{
automock: Type.Boolean(),
bail: Type.Union([Type.Boolean(), Type.Number()]),
cache: Type.Boolean(),
cacheDirectory: Type.String(),
ci: Type.Boolean(),
clearMocks: Type.Boolean(),
changedFilesWithAncestor: Type.Boolean(),
changedSince: Type.String(),
collectCoverage: Type.Boolean(),
collectCoverageFrom: Type.Array(Type.String()),
coverageDirectory: Type.String(),
coveragePathIgnorePatterns: Type.Array(Type.String()),
coverageProvider: RawCoverageProvider,
coverageReporters: RawCoverageReporters,
coverageThreshold: RawCoverageThreshold,
dependencyExtractor: Type.String(),
detectLeaks: Type.Boolean(),
detectOpenHandles: Type.Boolean(),
displayName: Type.Union([Type.String(), RawDisplayName]),
expand: Type.Boolean(),
extensionsToTreatAsEsm: Type.Array(Type.String()),
fakeTimers: RawFakeTimers,
filter: Type.String(),
findRelatedTests: Type.Boolean(),
forceCoverageMatch: Type.Array(Type.String()),
forceExit: Type.Boolean(),
json: Type.Boolean(),
globals: Type.Record(Type.String(), Type.Unknown()),
globalSetup: Type.Union([Type.String(), Type.Null()]),
globalTeardown: Type.Union([Type.String(), Type.Null()]),
haste: RawHasteConfig,
id: Type.String(),
injectGlobals: Type.Boolean(),
reporters: Type.Array(
Type.Union([
Type.String(),
Type.Tuple([
Type.String(),
Type.Record(Type.String(), Type.Unknown()),
]),
]),
),
logHeapUsage: Type.Boolean(),
lastCommit: Type.Boolean(),
listTests: Type.Boolean(),
maxConcurrency: Type.Integer(),
maxWorkers: Type.Union([Type.String(), Type.Integer()]),
moduleDirectories: Type.Array(Type.String()),
moduleFileExtensions: Type.Array(Type.String()),
moduleNameMapper: Type.Record(
Type.String(),
Type.Tuple([Type.String(), Type.Record(Type.String(), Type.Unknown())]),
]),
),
logHeapUsage: Type.Boolean(),
lastCommit: Type.Boolean(),
listTests: Type.Boolean(),
maxConcurrency: Type.Integer(),
maxWorkers: Type.Union([Type.String(), Type.Integer()]),
moduleDirectories: Type.Array(Type.String()),
moduleFileExtensions: Type.Array(Type.String()),
moduleNameMapper: Type.Record(
Type.String(),
Type.Union([Type.String(), Type.Array(Type.String())]),
),
modulePathIgnorePatterns: Type.Array(Type.String()),
modulePaths: Type.Array(Type.String()),
noStackTrace: Type.Boolean(),
notify: Type.Boolean(),
notifyMode: Type.String(),
onlyChanged: Type.Boolean(),
onlyFailures: Type.Boolean(),
openHandlesTimeout: Type.Number(),
outputFile: Type.String(),
passWithNoTests: Type.Boolean(),
preset: Type.Union([Type.String(), Type.Null()]),
prettierPath: Type.Union([Type.String(), Type.Null()]),
projects: Type.Array(
Type.Union([
Type.Union([Type.String(), Type.Array(Type.String())]),
),
modulePathIgnorePatterns: Type.Array(Type.String()),
modulePaths: Type.Array(Type.String()),
noStackTrace: Type.Boolean(),
notify: Type.Boolean(),
notifyMode: Type.String(),
onlyChanged: Type.Boolean(),
onlyFailures: Type.Boolean(),
openHandlesTimeout: Type.Number(),
outputFile: Type.String(),
passWithNoTests: Type.Boolean(),
preset: Type.Union([Type.String(), Type.Null()]),
prettierPath: Type.Union([Type.String(), Type.Null()]),
projects: Type.Array(
Type.Union([
Type.String(),
// TODO: Make sure to type these correctly
Type.Record(Type.String(), Type.Unknown()),
]),
),
randomize: Type.Boolean(),
replname: Type.Union([Type.String(), Type.Null()]),
resetMocks: Type.Boolean(),
resetModules: Type.Boolean(),
resolver: Type.Union([Type.String(), Type.Null()]),
restoreMocks: Type.Boolean(),
rootDir: Type.String(),
roots: Type.Array(Type.String()),
runner: Type.String(),
runTestsByPath: Type.Boolean(),
runtime: Type.String(),
sandboxInjectedGlobals: Type.Array(Type.String()),
setupFiles: Type.Array(Type.String()),
setupFilesAfterEnv: Type.Array(Type.String()),
showSeed: Type.Boolean(),
silent: Type.Boolean(),
skipFilter: Type.Boolean(),
skipNodeResolution: Type.Boolean(),
slowTestThreshold: Type.Number(),
snapshotResolver: Type.String(),
snapshotSerializers: Type.Array(Type.String()),
snapshotFormat: RawSnapshotFormat,
errorOnDeprecated: Type.Boolean(),
testEnvironment: Type.String(),
testEnvironmentOptions: Type.Record(Type.String(), Type.Unknown()),
testFailureExitCode: Type.Union([Type.String(), Type.Integer()]),
testLocationInResults: Type.Boolean(),
testMatch: Type.Array(Type.String()),
testNamePattern: Type.String(),
testPathIgnorePatterns: Type.Array(Type.String()),
testRegex: Type.Union([Type.String(), Type.Array(Type.String())]),
testResultsProcessor: Type.String(),
testRunner: Type.String(),
testSequencer: Type.String(),
testTimeout: Type.Number(),
transform: Type.Record(
Type.String(),
// TODO: Make sure to type these correctly
Type.Record(Type.String(), Type.Unknown()),
]),
),
randomize: Type.Boolean(),
replname: Type.Union([Type.String(), Type.Null()]),
resetMocks: Type.Boolean(),
resetModules: Type.Boolean(),
resolver: Type.Union([Type.String(), Type.Null()]),
restoreMocks: Type.Boolean(),
rootDir: Type.String(),
roots: Type.Array(Type.String()),
runner: Type.String(),
runTestsByPath: Type.Boolean(),
runtime: Type.String(),
sandboxInjectedGlobals: Type.Array(Type.String()),
setupFiles: Type.Array(Type.String()),
setupFilesAfterEnv: Type.Array(Type.String()),
showSeed: Type.Boolean(),
silent: Type.Boolean(),
skipFilter: Type.Boolean(),
skipNodeResolution: Type.Boolean(),
slowTestThreshold: Type.Number(),
snapshotResolver: Type.String(),
snapshotSerializers: Type.Array(Type.String()),
snapshotFormat: RawSnapshotFormat,
errorOnDeprecated: Type.Boolean(),
testEnvironment: Type.String(),
testEnvironmentOptions: Type.Record(Type.String(), Type.Unknown()),
testFailureExitCode: Type.Union([Type.String(), Type.Integer()]),
testLocationInResults: Type.Boolean(),
testMatch: Type.Array(Type.String()),
testNamePattern: Type.String(),
testPathIgnorePatterns: Type.Array(Type.String()),
testRegex: Type.Union([Type.String(), Type.Array(Type.String())]),
testResultsProcessor: Type.String(),
testRunner: Type.String(),
testSequencer: Type.String(),
testTimeout: Type.Number(),
transform: Type.Record(
Type.String(),
Type.Union([Type.String(), Type.Tuple([Type.String(), Type.Unknown()])]),
),
transformIgnorePatterns: Type.Array(Type.String()),
watchPathIgnorePatterns: Type.Array(Type.String()),
unmockedModulePathPatterns: Type.Array(Type.String()),
updateSnapshot: Type.Boolean(),
useStderr: Type.Boolean(),
verbose: Type.Boolean(),
waitNextEventLoopTurnForUnhandledRejectionEvents: Type.Boolean(),
watch: Type.Boolean(),
watchAll: Type.Boolean(),
watchman: Type.Boolean(),
watchPlugins: Type.Array(
Type.Union([Type.String(), Type.Tuple([Type.String(), Type.Unknown()])]),
),
workerIdleMemoryLimit: Type.Union([Type.Number(), Type.String()]),
workerThreads: Type.Boolean(),
}),
Type.Union([
Type.String(),
Type.Tuple([Type.String(), Type.Unknown()]),
]),
),
transformIgnorePatterns: Type.Array(Type.String()),
watchPathIgnorePatterns: Type.Array(Type.String()),
unmockedModulePathPatterns: Type.Array(Type.String()),
updateSnapshot: Type.Boolean(),
useStderr: Type.Boolean(),
verbose: Type.Boolean(),
waitNextEventLoopTurnForUnhandledRejectionEvents: Type.Boolean(),
watch: Type.Boolean(),
watchAll: Type.Boolean(),
watchman: Type.Boolean(),
watchPlugins: Type.Array(
Type.Union([
Type.String(),
Type.Tuple([Type.String(), Type.Unknown()]),
]),
),
workerIdleMemoryLimit: Type.Union([Type.Number(), Type.String()]),
workerThreads: Type.Boolean(),
},
{
title: 'Jest Initial Options',
description: "All of Jest's available configuration options",
$schema: 'http://json-schema.org/draft-07/schema',
},
),
);
25 changes: 25 additions & 0 deletions website/generateSchemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const fs = require('fs');
const path = require('path');

const nextConfigSchema = require('@jest/schemas').InitialOptions;

const schemasDirectory = path.resolve(__dirname, 'static/schemas');

fs.mkdirSync(schemasDirectory, {recursive: true});

fs.writeFileSync(
path.resolve(schemasDirectory, 'next.json'),
JSON.stringify({
...nextConfigSchema,
$id: 'https://jestjs.io/schemas/next.json',
})
);
4 changes: 3 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"fetchSupporters": "node fetchSupporters.js",
"generateSchemas": "node generateSchemas.js",
"netlify:ci:production": "yarn netlify:prepare && yarn netlify:crowdin && yarn build",
"netlify:ci:deployPreview": "yarn netlify:prepare && yarn build -l en",
"netlify:prepare": "yarn fetchSupporters && yarn build:js",
"netlify:prepare": "yarn fetchSupporters && yarn generateSchemas && yarn build:js",
"netlify:crowdin": "yarn write-translations && yarn crowdin:upload && yarn crowdin:download",
"typecheck": "tsc"
},
Expand Down Expand Up @@ -51,6 +52,7 @@
"@crowdin/cli": "^3.5.2",
"@docusaurus/module-type-aliases": "^3.0.0",
"@docusaurus/tsconfig": "^3.0.0",
"@jest/schemas": "workspace:*",
Copy link
Member Author

@SimenB SimenB Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add "@jest/schemas-30x": "npm:@jest/schemas@^30" etc later for different versions

"@types/react": "^18.2.0",
"graphql": "^16.3.0",
"graphql-request": "^6.0.0",
Expand Down
8 changes: 8 additions & 0 deletions website/static/_redirects
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@

# Redirect Docusaurus v1 blog RSS feed
/blog/feed.xml /blog/rss.xml

# JSON Schemas
# TODO: should be `latest.json`, not `next.json`, when we actually publish a version with a schema
/schema.json /static/schemas/next.json 200
/schemas/latest.json /static/schemas/next.json 200
/schemas/30.0.json /static/schemas/next.json 200
/schemas/30.x.json /static/schemas/next.json 200
/schemas/next.json /static/schemas/next.json 200
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13507,6 +13507,7 @@ __metadata:
"@docusaurus/preset-classic": ^3.0.0
"@docusaurus/remark-plugin-npm2yarn": ^3.0.0
"@docusaurus/tsconfig": ^3.0.0
"@jest/schemas": "workspace:*"
"@types/react": ^18.2.0
clsx: ^2.0.0
docusaurus-remark-plugin-tab-blocks: ^3.0.0
Expand Down