Skip to content

Commit

Permalink
Update Jest globals (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 21, 2024
1 parent 8314faf commit ca7c300
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
6 changes: 3 additions & 3 deletions data/jest.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// This file is autogenerated by scripts
// Do NOT modify this file manually

export default {
afterAll: false,
afterEach: false,
beforeAll: false,
beforeEach: false,
describe: false,
expect: false,
fdescribe: false,
fit: false,
it: false,
jest: false,
pit: false,
require: false,
test: false,
xdescribe: false,
xit: false,
Expand Down
3 changes: 0 additions & 3 deletions globals.json
Original file line number Diff line number Diff line change
Expand Up @@ -1923,12 +1923,9 @@
"beforeEach": false,
"describe": false,
"expect": false,
"fdescribe": false,
"fit": false,
"it": false,
"jest": false,
"pit": false,
"require": false,
"test": false,
"xdescribe": false,
"xit": false,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"update:nodeBuiltin": "node scripts/update.mjs --environment=nodeBuiltin",
"update:worker": "node scripts/update.mjs --environment=worker",
"update:shelljs": "node scripts/update.mjs --environment=shelljs",
"update:jest": "node scripts/update.mjs --environment=jest",
"build": "run-s build:data build:types",
"build": "run-p \"build:*\"",
"build:data": "node scripts/generate-data.mjs",
"build:types": "node scripts/generate-types.mjs"
},
Expand All @@ -46,6 +46,7 @@
"devDependencies": {
"ava": "^6.1.1",
"cheerio": "^1.0.0-rc.12",
"eslint-plugin-jest": "^27.9.0",
"execa": "^8.0.1",
"get-port": "^7.0.0",
"npm-run-all2": "^6.1.2",
Expand Down
8 changes: 8 additions & 0 deletions scripts/get-jest-globals.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import module from 'node:module';

// https://github.com/jest-community/eslint-plugin-jest/blob/main/src/globals.json
export default function getJestGlobals() {
const require = module.createRequire(import.meta.url);
const globals = require('eslint-plugin-jest/lib/globals.json');
return globals;
}
15 changes: 11 additions & 4 deletions scripts/update.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import getBuiltinGlobals from './get-builtin-globals.mjs';
import getNodeBuiltinGlobals from './get-node-builtin-globals.mjs';
import {getBrowserGlobals, getWebWorkerGlobals} from './get-browser-globals.mjs';
import getShelljsGlobals from './get-shelljs-globals.mjs';
import getJestGlobals from './get-jest-globals.mjs';
import {updateGlobals} from './utilities.mjs';

const ALL_JOBS = [
Expand All @@ -27,6 +28,12 @@ const ALL_JOBS = [
{
environment: 'shelljs',
getGlobals: getShelljsGlobals,
incremental: false,
},
{
environment: 'jest',
getGlobals: getJestGlobals,
incremental: false,
},
];

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

for (const {environment, getGlobals} of jobs) {
for (const {environment, getGlobals, incremental = false} of jobs) {
const {
added,
removed,
Expand All @@ -44,8 +51,8 @@ async function run(options) {
= await updateGlobals({
environment,
getGlobals,
dry: options.dry,
clean: options.clean,
dryRun: options.dry,
incremental: incremental ?? !options.clean,
});

console.log(`✅ ${environment} globals updated.`);
Expand All @@ -54,7 +61,7 @@ async function run(options) {
console.log();
console.log(
outdent`
Added(${removed.length}):
Added(${added.length}):
${added.map(name => ` + ${name}`).join('\n')}
`,
);
Expand Down
6 changes: 3 additions & 3 deletions scripts/utilities.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ const writeGlobals = async (environment, globals) => {
await fs.writeFile(file, code + '\n');
};

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

if (!clean) {
if (incremental) {
updated = {...original, ...updated};
}

if (!dry) {
if (!dryRun) {
await writeGlobals(environment, updated);
}

Expand Down

0 comments on commit ca7c300

Please sign in to comment.