Skip to content

Commit 398a46b

Browse files
committed
refactor: cosmetics and formatting
1 parent f7e7281 commit 398a46b

18 files changed

Lines changed: 133 additions & 116 deletions

.all-contributorsrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,3 @@
229229
],
230230
"commitConvention": "angular"
231231
}
232-

.remarkrc.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
/**
8-
* Remark configuration loaded when `NODE_ENV == 'lint'`. The goal here is to
8+
* Remark configuration loaded when `NODE_ENV === 'lint'`. The goal here is to
99
* check for things that will not be corrected by prettier or remark during a
1010
* formatting pass (see below).
1111
*
@@ -54,7 +54,7 @@ const lintConfig = {
5454
};
5555

5656
/**
57-
* Remark configuration loaded when `NODE_ENV == 'format'`. The goal here is to
57+
* Remark configuration loaded when `NODE_ENV === 'format'`. The goal here is to
5858
* correct things that will not be taken care of by prettier.
5959
*
6060
* @type {Config}
@@ -89,9 +89,9 @@ export default {
8989
rule: '-',
9090
strong: '*',
9191
tightDefinitions: true,
92-
...(process.env.NODE_ENV == 'lint' ? lintConfig.settings : formatConfig.settings)
92+
...(process.env.NODE_ENV === 'lint' ? lintConfig.settings : formatConfig.settings)
9393
},
9494
plugins: [
95-
...(process.env.NODE_ENV == 'lint' ? lintConfig.plugins : formatConfig.plugins)
95+
...(process.env.NODE_ENV === 'lint' ? lintConfig.plugins : formatConfig.plugins)
9696
]
9797
};

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
'explicit-exports-references'
2929
]
3030
},
31-
// * Used when NODE_ENV == production (usually for generating types w/ tsc)
31+
// * Used when NODE_ENV === production (usually for generating types w/ tsc)
3232
production: {
3333
presets: [
3434
[

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ module.exports = {
1414
60 *
1515
(process.env.VSCODE_INSPECTOR_OPTIONS
1616
? 60 * 24
17-
: process.platform == 'win32'
18-
? 5
19-
: 1),
17+
: process.platform === 'win32'
18+
? 5
19+
: 1),
2020
// ? Minimum of 2 concurrent tests executed at once; maximum of cpu cores - 1
2121
maxConcurrency: Math.max(require('node:os').cpus().length - 1, 2),
2222
verbose: false,

src/errors.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const ErrorMessage = {
8080
| Pick<PluginTesterTestFixtureConfig, typeof $type | 'fixtureOutputBasename'>
8181
) => {
8282
return `actual output does not match ${
83-
testConfig[$type] == 'fixture-object'
83+
testConfig[$type] === 'fixture-object'
8484
? testConfig.fixtureOutputBasename
8585
: 'expected output'
8686
}`;
@@ -103,29 +103,29 @@ export const ErrorMessage = {
103103
InvalidHasThrowsAndOutput: (
104104
testConfig: Pick<MaybePluginTesterTestConfig, typeof $type>
105105
) => {
106-
return testConfig[$type] == 'test-object'
106+
return testConfig[$type] === 'test-object'
107107
? 'neither `output` nor `outputFixture` can be provided with `throws` or `error`'
108108
: 'a fixture cannot be provided with `throws` or `error` and also contain an output file';
109109
},
110110
InvalidHasThrowsAndExec: (
111111
testConfig: Pick<MaybePluginTesterTestConfig, typeof $type>
112112
) => {
113-
return testConfig[$type] == 'test-object'
113+
return testConfig[$type] === 'test-object'
114114
? 'neither `exec` nor `execFixture` can be provided with `throws` or `error`'
115115
: 'a fixture cannot be provided with `throws` or `error` and also contain an exec file';
116116
},
117117
InvalidMissingCodeOrExec: (
118118
testConfig: Pick<MaybePluginTesterTestConfig, typeof $type>
119119
) => {
120120
/* istanbul ignore next */
121-
return testConfig[$type] == 'test-object'
121+
return testConfig[$type] === 'test-object'
122122
? 'a string or object with a `code`, `codeFixture`, `fixture`, `exec`, or `execFixture` must be provided'
123123
: 'a fixture must contain either a code file or an exec file';
124124
},
125125
InvalidHasExecAndCodeOrOutput: (
126126
testConfig: Pick<MaybePluginTesterTestConfig, typeof $type>
127127
) => {
128-
return testConfig[$type] == 'test-object'
128+
return testConfig[$type] === 'test-object'
129129
? 'neither `code`, `codeFixture`, `fixture`, `output`, nor `outputFixture` can be provided with `exec` or `execFixture`'
130130
: 'a fixture cannot contain both an exec file and a code or output file';
131131
},

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { PluginTesterOptions } from './types';
1313

1414
const debug = debugFactory('babel-plugin-tester:index');
1515

16-
if ('expect' in globalThis && typeof expect?.addSnapshotSerializer == 'function') {
16+
if ('expect' in globalThis && typeof expect?.addSnapshotSerializer === 'function') {
1717
debug(
1818
'added unstring snapshot serializer globally; all snapshots after this point will be affected'
1919
);

src/plugin-tester.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ function restartTestTitleNumbering() {
115115
function pluginTester(options: PluginTesterOptions = {}) {
116116
debug1('executing main babel-plugin-tester function');
117117

118-
const globalContextHasExpectFn = 'expect' in globalThis && typeof expect == 'function';
119-
const globalContextHasTestFn = 'it' in globalThis && typeof it == 'function';
118+
const globalContextHasExpectFn = 'expect' in globalThis && typeof expect === 'function';
119+
const globalContextHasTestFn = 'it' in globalThis && typeof it === 'function';
120120

121121
const globalContextHasDescribeFn =
122-
'describe' in globalThis && typeof describe == 'function';
122+
'describe' in globalThis && typeof describe === 'function';
123123

124124
const globalContextExpectFnHasToMatchSnapshot = (() => {
125125
try {
126126
return globalContextHasExpectFn
127-
? typeof expect(undefined)?.toMatchSnapshot == 'function'
127+
? typeof expect(undefined)?.toMatchSnapshot === 'function'
128128
: false;
129129
} catch {
130130
/* istanbul ignore next */
@@ -133,11 +133,11 @@ function pluginTester(options: PluginTesterOptions = {}) {
133133
})();
134134

135135
const globalContextTestFnHasSkip = globalContextHasTestFn
136-
? typeof it.skip == 'function'
136+
? typeof it.skip === 'function'
137137
: false;
138138

139139
const globalContextTestFnHasOnly = globalContextHasTestFn
140-
? typeof it.only == 'function'
140+
? typeof it.only === 'function'
141141
: false;
142142

143143
if (!globalContextHasDescribeFn) {
@@ -253,7 +253,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
253253
throw new TypeError(ErrorMessage.BadConfigInvalidTestsArrayItemType(ndx));
254254
}
255255

256-
const result = typeof test == 'string' || Boolean(test);
256+
const result = typeof test === 'string' || Boolean(test);
257257

258258
if (!result) {
259259
debug2(`test item \`%O\` at index ${ndx} was skipped`, test);
@@ -275,7 +275,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
275275
);
276276
}
277277

278-
const result = typeof test == 'string' || Boolean(test);
278+
const result = typeof test === 'string' || Boolean(test);
279279

280280
if (!result) {
281281
debug2(`test property "${title}" with value \`%O\` was skipped`, test);
@@ -369,7 +369,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
369369
functionName,
370370
// ? Just in case the script name/path has colons
371371
filePath: filePath
372-
.split(`file://${process.platform == 'win32' ? '/' : ''}`)
372+
.split(`file://${process.platform === 'win32' ? '/' : ''}`)
373373
.at(-1)!
374374
.split(':')
375375
.slice(0, -2)
@@ -406,19 +406,19 @@ function pluginTester(options: PluginTesterOptions = {}) {
406406
return [
407407
reversedCallStack.findIndex(({ functionName, filePath }) => {
408408
return (
409-
functionName == 'defaultPluginTester' &&
409+
functionName === 'defaultPluginTester' &&
410410
parseScriptFilepathRegExp.test(filePath)
411411
);
412412
}),
413413
reversedCallStack.findIndex(({ functionName, filePath }) => {
414414
return (
415-
functionName == 'pluginTester' &&
415+
functionName === 'pluginTester' &&
416416
/* istanbul ignore next */ parseScriptFilepathRegExp.test(filePath)
417417
);
418418
}),
419419
reversedCallStack.findIndex(({ functionName, filePath }) => {
420420
return (
421-
functionName == 'resolveBaseConfig' &&
421+
functionName === 'resolveBaseConfig' &&
422422
parseScriptFilepathRegExp.test(filePath)
423423
);
424424
})
@@ -469,7 +469,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
469469
throw new TypeError(
470470
ErrorMessage.BadEnvironmentVariableRange(name, s, range)
471471
);
472-
} else if (start == end) {
472+
} else if (start === end) {
473473
return start;
474474
}
475475

@@ -494,10 +494,11 @@ function pluginTester(options: PluginTesterOptions = {}) {
494494
const testConfigs: PluginTesterTestConfig[] = [];
495495

496496
const useFixtureTitleNumbering =
497-
baseConfig.titleNumbering == 'all' || baseConfig.titleNumbering == 'fixtures-only';
497+
baseConfig.titleNumbering === 'all' ||
498+
baseConfig.titleNumbering === 'fixtures-only';
498499

499500
const useTestObjectTitleNumbering =
500-
baseConfig.titleNumbering == 'all' || baseConfig.titleNumbering == 'tests-only';
501+
baseConfig.titleNumbering === 'all' || baseConfig.titleNumbering === 'tests-only';
501502

502503
if (fixturesAbsolutePath) {
503504
debug2(
@@ -509,7 +510,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
509510
debug2('generating test objects from fixtures path');
510511

511512
const describeBlock =
512-
typeof describeBlockTitle == 'string'
513+
typeof describeBlockTitle === 'string'
513514
? createAndPushDescribeConfig(`${describeBlockTitle} fixtures`)
514515
: undefined;
515516

@@ -524,7 +525,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
524525
} else {
525526
debug2('not generating test objects from fixtures path: path is not a directory');
526527
}
527-
} else if (typeof fixtures == 'string') {
528+
} else if (typeof fixtures === 'string') {
528529
throw new TypeError(
529530
ErrorMessage.UnableToDeriveAbsolutePath(
530531
filepath,
@@ -541,7 +542,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
541542
debug2('generating test objects from tests');
542543

543544
const describeBlock =
544-
typeof describeBlockTitle == 'string'
545+
typeof describeBlockTitle === 'string'
545546
? createAndPushDescribeConfig(describeBlockTitle)
546547
: undefined;
547548

@@ -561,7 +562,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
561562
...entries.map(([title, test]) => {
562563
return createTestConfig({
563564
title,
564-
...(typeof test == 'string' ? { code: test } : test)
565+
...(typeof test === 'string' ? { code: test } : test)
565566
});
566567
})
567568
);
@@ -988,7 +989,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
988989
debug2(`registering ${tests.length} blocks with testing framework`);
989990

990991
tests.forEach((testConfig) => {
991-
if (testConfig[$type] == 'describe-block') {
992+
if (testConfig[$type] === 'describe-block') {
992993
debug2(
993994
`registering describe block "${testConfig.describeBlockTitle}" and its sub-blocks`
994995
);
@@ -1228,7 +1229,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
12281229
// @ts-expect-error: not sure from the docs if this is a type error
12291230
microtaskMode: 'afterEvaluate'
12301231
});
1231-
} else if (testConfig[$type] == 'test-object' && testConfig.snapshot) {
1232+
} else if (testConfig[$type] === 'test-object' && testConfig.snapshot) {
12321233
debug2('expecting output from babel transform function to match snapshot');
12331234

12341235
assert(
@@ -1250,7 +1251,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
12501251
output,
12511252
ErrorMessage.ExpectedOutputToEqualActual(testConfig)
12521253
);
1253-
} else if (testConfig[$type] == 'fixture-object' && outputFixture) {
1254+
} else if (testConfig[$type] === 'fixture-object' && outputFixture) {
12541255
debug2('writing output from babel transform function to new output file');
12551256
fs.writeFileSync(outputFixture, result);
12561257
} else {
@@ -1313,7 +1314,7 @@ function pluginTester(options: PluginTesterOptions = {}) {
13131314
}
13141315
}
13151316

1316-
if (testConfig[$type] == 'test-object' && testConfig.snapshot) {
1317+
if (testConfig[$type] === 'test-object' && testConfig.snapshot) {
13171318
if (!globalContextExpectFnHasToMatchSnapshot) {
13181319
throwTypeErrorWithDebugOutput(ErrorMessage.TestEnvironmentNoSnapshotSupport());
13191320
}
@@ -1422,10 +1423,10 @@ function getAbsolutePathUsingFilepathDirname(filepath?: string, basename?: strin
14221423
const result = !basename
14231424
? undefined
14241425
: path.isAbsolute(basename)
1425-
? basename
1426-
: filepath
1427-
? path.join(path.dirname(filepath), basename)
1428-
: undefined;
1426+
? basename
1427+
: filepath
1428+
? path.join(path.dirname(filepath), basename)
1429+
: undefined;
14291430

14301431
verbose2(`dirname(${filepath}) + ${basename} => ${result}`);
14311432
return result;
@@ -1479,7 +1480,7 @@ function readCode(filepath: string | undefined, basename?: string): string | und
14791480
const { verbose: verbose2 } = getDebuggers('read-code', debug1);
14801481

14811482
const codePath =
1482-
arguments.length == 1
1483+
arguments.length === 1
14831484
? filepath
14841485
: getAbsolutePathUsingFilepathDirname(filepath, basename);
14851486

@@ -1635,10 +1636,10 @@ function numericPrefixInRanges(
16351636
numericPrefix: number | undefined,
16361637
ranges: (number | Range)[]
16371638
) {
1638-
if (typeof numericPrefix == 'number') {
1639+
if (typeof numericPrefix === 'number') {
16391640
return ranges.some((range) => {
1640-
return typeof range == 'number'
1641-
? numericPrefix == range
1641+
return typeof range === 'number'
1642+
? numericPrefix === range
16421643
: numericPrefix >= range.start && numericPrefix <= range.end;
16431644
});
16441645
}

test/examples/example-3.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pluginTester({
5454
// You can provide tests as an object
5555
tests: {
5656
// The key is the title. The value is the code that is unchanged (because
57-
// snapshot == false across all tests). Test title will be: "1. does not
57+
// snapshot === false across all tests). Test title will be: "1. does not
5858
// change code with no identifiers"
5959
'does not change code with no identifiers': '"hello";',
6060

test/examples/example-4.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pluginTester({
5555

5656
// Alternatively, you can provide tests as an array
5757
tests: [
58-
// Should be unchanged by the plugin (because snapshot == false across all
58+
// Should be unchanged by the plugin (because snapshot === false across all
5959
// tests). Test title will be: "1. identifier reverse"
6060
'"hello";',
6161
{

test/helpers/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { type AssertionError } from 'node:assert';
12
import fs from 'node:fs';
23
import path from 'node:path';
3-
import { type AssertionError } from 'node:assert';
44
import { types } from 'node:util';
55

66
import { pluginTester } from '../../src/plugin-tester';
@@ -105,7 +105,7 @@ export function addRunnableJestTest(
105105
}
106106

107107
function isAssertionError(error: Error): error is AssertionError {
108-
return error.name == 'AssertionError';
108+
return error.name === 'AssertionError';
109109
}
110110
});
111111
}
@@ -192,7 +192,7 @@ export async function runPluginTester(options?: PluginTesterOptions) {
192192
await pendingTests[pendingTests.push(test()) - 1];
193193
}
194194

195-
return pendingTests;
195+
//return pendingTests;
196196
} finally {
197197
runnableJestTests = [];
198198
}

0 commit comments

Comments
 (0)