Skip to content

Commit ca7c300

Browse files
authored
Update Jest globals (#235)
1 parent 8314faf commit ca7c300

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

data/jest.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
// This file is autogenerated by scripts
2+
// Do NOT modify this file manually
3+
14
export default {
25
afterAll: false,
36
afterEach: false,
47
beforeAll: false,
58
beforeEach: false,
69
describe: false,
710
expect: false,
8-
fdescribe: false,
911
fit: false,
1012
it: false,
1113
jest: false,
12-
pit: false,
13-
require: false,
1414
test: false,
1515
xdescribe: false,
1616
xit: false,

globals.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,12 +1923,9 @@
19231923
"beforeEach": false,
19241924
"describe": false,
19251925
"expect": false,
1926-
"fdescribe": false,
19271926
"fit": false,
19281927
"it": false,
19291928
"jest": false,
1930-
"pit": false,
1931-
"require": false,
19321929
"test": false,
19331930
"xdescribe": false,
19341931
"xit": false,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"update:nodeBuiltin": "node scripts/update.mjs --environment=nodeBuiltin",
2424
"update:worker": "node scripts/update.mjs --environment=worker",
2525
"update:shelljs": "node scripts/update.mjs --environment=shelljs",
26+
"update:jest": "node scripts/update.mjs --environment=jest",
2627
"build": "run-s build:data build:types",
27-
"build": "run-p \"build:*\"",
2828
"build:data": "node scripts/generate-data.mjs",
2929
"build:types": "node scripts/generate-types.mjs"
3030
},
@@ -46,6 +46,7 @@
4646
"devDependencies": {
4747
"ava": "^6.1.1",
4848
"cheerio": "^1.0.0-rc.12",
49+
"eslint-plugin-jest": "^27.9.0",
4950
"execa": "^8.0.1",
5051
"get-port": "^7.0.0",
5152
"npm-run-all2": "^6.1.2",

scripts/get-jest-globals.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import module from 'node:module';
2+
3+
// https://github.com/jest-community/eslint-plugin-jest/blob/main/src/globals.json
4+
export default function getJestGlobals() {
5+
const require = module.createRequire(import.meta.url);
6+
const globals = require('eslint-plugin-jest/lib/globals.json');
7+
return globals;
8+
}

scripts/update.mjs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import getBuiltinGlobals from './get-builtin-globals.mjs';
55
import getNodeBuiltinGlobals from './get-node-builtin-globals.mjs';
66
import {getBrowserGlobals, getWebWorkerGlobals} from './get-browser-globals.mjs';
77
import getShelljsGlobals from './get-shelljs-globals.mjs';
8+
import getJestGlobals from './get-jest-globals.mjs';
89
import {updateGlobals} from './utilities.mjs';
910

1011
const ALL_JOBS = [
@@ -27,6 +28,12 @@ const ALL_JOBS = [
2728
{
2829
environment: 'shelljs',
2930
getGlobals: getShelljsGlobals,
31+
incremental: false,
32+
},
33+
{
34+
environment: 'jest',
35+
getGlobals: getJestGlobals,
36+
incremental: false,
3037
},
3138
];
3239

@@ -35,7 +42,7 @@ async function run(options) {
3542
? ALL_JOBS.filter(job => job.environment === options.environment)
3643
: ALL_JOBS;
3744

38-
for (const {environment, getGlobals} of jobs) {
45+
for (const {environment, getGlobals, incremental = false} of jobs) {
3946
const {
4047
added,
4148
removed,
@@ -44,8 +51,8 @@ async function run(options) {
4451
= await updateGlobals({
4552
environment,
4653
getGlobals,
47-
dry: options.dry,
48-
clean: options.clean,
54+
dryRun: options.dry,
55+
incremental: incremental ?? !options.clean,
4956
});
5057

5158
console.log(`✅ ${environment} globals updated.`);
@@ -54,7 +61,7 @@ async function run(options) {
5461
console.log();
5562
console.log(
5663
outdent`
57-
Added(${removed.length}):
64+
Added(${added.length}):
5865
${added.map(name => ` + ${name}`).join('\n')}
5966
`,
6067
);

scripts/utilities.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ const writeGlobals = async (environment, globals) => {
1919
await fs.writeFile(file, code + '\n');
2020
};
2121

22-
async function updateGlobals({environment, getGlobals, dry, clean}) {
22+
async function updateGlobals({environment, getGlobals, dryRun, incremental}) {
2323
let updated = await getGlobals();
2424
const original = await readGlobals(environment, {ignoreNonExits: true});
2525

26-
if (!clean) {
26+
if (incremental) {
2727
updated = {...original, ...updated};
2828
}
2929

30-
if (!dry) {
30+
if (!dryRun) {
3131
await writeGlobals(environment, updated);
3232
}
3333

0 commit comments

Comments
 (0)