Skip to content

Commit

Permalink
Merge branch 'main' into et/expose-config-in-test-sequencer
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 19, 2023
2 parents fe73276 + 0a45938 commit 5fc7262
Show file tree
Hide file tree
Showing 59 changed files with 429 additions and 411 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ module.exports = {
'wrap-regex': 'off',
yoda: 'off',

'unicorn/explicit-length-check': 'error',
'unicorn/no-negated-condition': 'error',
'unicorn/prefer-default-parameters': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/template-indent': 'error',
},
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Node CI
name: Node Nightly CI

on:
workflow_dispatch:
Expand Down Expand Up @@ -41,3 +41,12 @@ jobs:
needs: prepare-yarn-cache-windows
with:
os: windows-latest
notify:
name: Notify failed build
needs: [test-ubuntu, test-macos, test-windows]
if: failure()
runs-on: ubuntu-latest
steps:
- uses: jayqi/failed-build-issue-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions packages/expect-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const getPath = (
propertyPath = pathAsArray(propertyPath);
}

if (propertyPath.length) {
if (propertyPath.length > 0) {
const lastProp = propertyPath.length === 1;
const prop = propertyPath[0];
const newObject = object[prop];
Expand Down Expand Up @@ -482,7 +482,7 @@ export const isError = (value: unknown): value is Error => {
};

export function emptyObject(obj: unknown): boolean {
return obj && typeof obj === 'object' ? !Object.keys(obj).length : false;
return obj && typeof obj === 'object' ? Object.keys(obj).length === 0 : false;
}

const MULTILINE_REGEXP = /[\r\n]/;
Expand Down
6 changes: 3 additions & 3 deletions packages/expect/__typetests__/expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const allowOmittingExpected: MatcherFunction = (
actual: unknown,
...expect: Array<unknown>
) => {
if (expect.length !== 0) {
if (expect.length > 0) {
throw new Error('This matcher does not take any expected argument.');
}

Expand All @@ -194,7 +194,7 @@ const toHaveContext: MatcherFunction = function (
) {
expectType<MatcherContext>(this);

if (expect.length !== 0) {
if (expect.length > 0) {
throw new Error('This matcher does not take any expected argument.');
}

Expand All @@ -215,7 +215,7 @@ const customContext: MatcherFunctionWithContext<CustomContext> = function (
expectType<CustomContext>(this);
expectType<void>(this.customMethod());

if (expect.length !== 0) {
if (expect.length > 0) {
throw new Error('This matcher does not take any expected argument.');
}

Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const getPromiseMatcher = (name: string, matcher: RawMatcherFn) => {
};

export const expect: Expect = (actual: any, ...rest: Array<any>) => {
if (rest.length !== 0) {
if (rest.length > 0) {
throw new Error('Expect takes at most one argument.');
}

Expand Down
4 changes: 2 additions & 2 deletions packages/expect/src/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export const printReceivedConstructorNameNot = (
expected: Function,
): string =>
typeof expected.name === 'string' &&
expected.name.length !== 0 &&
expected.name.length > 0 &&
typeof received.name === 'string' &&
received.name.length !== 0
received.name.length > 0
? `${printConstructorName(label, received, true, false)} ${
Object.getPrototypeOf(received) === expected
? 'extends'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const runAndTransformResultsToJestFormat = async ({
} else if (testResult.status === 'todo') {
status = 'todo';
numTodoTests += 1;
} else if (testResult.errors.length) {
} else if (testResult.errors.length > 0) {
status = 'failed';
numFailingTests += 1;
} else {
Expand Down Expand Up @@ -197,7 +197,7 @@ export const runAndTransformResultsToJestFormat = async ({
);
let testExecError;

if (runResult.unhandledErrors.length) {
if (runResult.unhandledErrors.length > 0) {
testExecError = {
message: '',
stack: runResult.unhandledErrors.join('\n'),
Expand Down Expand Up @@ -261,7 +261,7 @@ const _addExpectedAssertionErrors = (test: Circus.TestEntry) => {
const _addSuppressedErrors = (test: Circus.TestEntry) => {
const {suppressedErrors} = jestExpect.getState();
jestExpect.setState({suppressedErrors: []});
if (suppressedErrors.length) {
if (suppressedErrors.length > 0) {
test.errors = test.errors.concat(suppressedErrors);
}
};
4 changes: 2 additions & 2 deletions packages/jest-circus/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const _runTest = async (
const {afterEach, beforeEach} = getEachHooksForTest(test);

for (const hook of beforeEach) {
if (test.errors.length) {
if (test.errors.length > 0) {
// If any of the before hooks failed already, we don't run any
// hooks after that.
break;
Expand Down Expand Up @@ -239,7 +239,7 @@ const _callCircusTest = async (
const timeout = test.timeout || getState().testTimeout;
invariant(test.fn, "Tests with no 'fn' should have 'mode' set to 'skipped'");

if (test.errors.length) {
if (test.errors.length > 0) {
return; // We don't run the test if there's already an error in before hooks.
}

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const getProjectListFromCLIArgs = (argv: Config.Argv, project?: string) => {
projects.push(project);
}

if (!projects.length && process.platform === 'win32') {
if (projects.length === 0 && process.platform === 'win32') {
try {
projects.push(tryRealpath(process.cwd()));
} catch {
Expand All @@ -101,7 +101,7 @@ const getProjectListFromCLIArgs = (argv: Config.Argv, project?: string) => {
}
}

if (!projects.length) {
if (projects.length === 0) {
projects.push(process.cwd());
}

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export async function readConfigs(
hasDeprecationWarnings = parsedConfig.hasDeprecationWarnings;
globalConfig = parsedConfig.globalConfig;
configs = [parsedConfig.projectConfig];
if (globalConfig.projects && globalConfig.projects.length) {
if (globalConfig.projects && globalConfig.projects.length > 0) {
// Even though we had one project in CLI args, there might be more
// projects defined in the config.
// In other words, if this was a single project,
Expand Down Expand Up @@ -418,7 +418,7 @@ export async function readConfigs(
}
}

if (!globalConfig || !configs.length) {
if (!globalConfig || configs.length === 0) {
throw new Error('jest: No configuration found for any project.');
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ export default async function normalize(
const globMatches =
typeof project === 'string' ? glob(project) : [];
return projects.concat(
globMatches.length ? globMatches : project,
globMatches.length > 0 ? globMatches : project,
);
},
[],
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-console/src/BufferedConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ export default class BufferedConsole extends Console {
}

getBuffer(): ConsoleBuffer | undefined {
return this._buffer.length ? this._buffer : undefined;
return this._buffer.length > 0 ? this._buffer : undefined;
}
}
2 changes: 1 addition & 1 deletion packages/jest-core/src/ReporterDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ export default class ReporterDispatcher {
}

hasErrors(): boolean {
return this.getErrors().length !== 0;
return this.getErrors().length > 0;
}
}
12 changes: 6 additions & 6 deletions packages/jest-core/src/SearchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ export default class SearchSource {
stat: 'roots',
});

if (config.testMatch.length) {
if (config.testMatch.length > 0) {
this._testPathCases.push({
isMatch: globsToMatcher(config.testMatch),
stat: 'testMatch',
});
}

if (config.testPathIgnorePatterns.length) {
if (config.testPathIgnorePatterns.length > 0) {
const testIgnorePatternsRegex = new RegExp(
config.testPathIgnorePatterns.join('|'),
);
Expand All @@ -89,7 +89,7 @@ export default class SearchSource {
});
}

if (config.testRegex.length) {
if (config.testRegex.length > 0) {
this._testPathCases.push({
isMatch: regexToMatcher(config.testRegex),
stat: 'testRegex',
Expand Down Expand Up @@ -239,7 +239,7 @@ export default class SearchSource {
paths: Array<string>,
collectCoverage: boolean,
): Promise<SearchResult> {
if (Array.isArray(paths) && paths.length) {
if (Array.isArray(paths) && paths.length > 0) {
const resolvedPaths = paths.map(p =>
path.resolve(this._context.config.cwd, p),
);
Expand Down Expand Up @@ -280,9 +280,9 @@ export default class SearchSource {
paths = this.filterPathsWin32(paths);
}

if (globalConfig.runTestsByPath && paths && paths.length) {
if (globalConfig.runTestsByPath && paths && paths.length > 0) {
return this.findTestsByPaths(paths);
} else if (globalConfig.findRelatedTests && paths && paths.length) {
} else if (globalConfig.findRelatedTests && paths && paths.length > 0) {
return this.findRelatedTestsFromPattern(
paths,
globalConfig.collectCoverage,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/SnapshotInteractiveMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default class SnapshotInteractiveMode {
shouldUpdateSnapshot: boolean,
) => unknown,
): void {
if (!failedSnapshotTestAssertions.length) {
if (failedSnapshotTestAssertions.length === 0) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export async function runCLI(

const {openHandles} = results;

if (openHandles && openHandles.length) {
if (openHandles && openHandles.length > 0) {
const formatted = formatHandleErrors(openHandles, configs[0]);

const openHandlesString = pluralize('open handle', formatted.length, 's');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin {
_globalConfig: Config.GlobalConfig,
updateConfigAndRun: Function,
): Promise<void> {
if (this._failedSnapshotTestAssertions.length) {
if (this._failedSnapshotTestAssertions.length > 0) {
return new Promise(res => {
this._snapshotInteractiveMode.run(
this._failedSnapshotTestAssertions,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const getTestPaths = async (
) => {
const data = await source.getTestPaths(globalConfig, changedFiles, filter);

if (!data.tests.length && globalConfig.onlyChanged && data.noSCM) {
if (data.tests.length === 0 && globalConfig.onlyChanged && data.noSCM) {
new CustomConsole(outputStream, outputStream).log(
'Jest can only find uncommitted changed files in a git or hg ' +
'repository. If you make your project a git or hg ' +
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export default async function watch(
isValidPath(globalConfig, filePath),
);

if (validPaths.length) {
if (validPaths.length > 0) {
const context = (contexts[index] = createContext(
contexts[index].config,
{hasteFS, moduleMap},
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-diff/src/getAlignedDiffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const concatenateRelevantDiffs = (
reduced +
(diff[0] === DIFF_EQUAL
? diff[1]
: diff[0] === op && diff[1].length !== 0 // empty if change is newline
: diff[0] === op && diff[1].length > 0 // empty if change is newline
? changeColor(diff[1])
: ''),
'',
Expand Down Expand Up @@ -88,7 +88,7 @@ class ChangeBuffer {
// A middle substring is a change line.
this.pushSubstring(substring);
this.pushLine();
} else if (substring.length !== 0) {
} else if (substring.length > 0) {
// The last substring starts a change line, if it is not empty.
// Important: This non-empty condition also automatically omits
// the newline appended to the end of expected and received strings.
Expand Down Expand Up @@ -173,7 +173,7 @@ class CommonBuffer {
} else if (i < iLast) {
// A middle substring is a common line.
this.pushDiffCommonLine(new Diff(op, substring));
} else if (substring.length !== 0) {
} else if (substring.length > 0) {
// The last substring starts a change line, if it is not empty.
// Important: This non-empty condition also automatically omits
// the newline appended to the end of expected and received strings.
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-diff/src/joinAlignedDiffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const printDiffLine = (
): string =>
line.length === 0
? indicator === ' '
? isFirstOrLast && emptyFirstOrLastLinePlaceholder.length !== 0
? isFirstOrLast && emptyFirstOrLastLinePlaceholder.length > 0
? color(`${indicator} ${emptyFirstOrLastLinePlaceholder}`)
: ''
: color(indicator)
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-diff/src/printDiffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const diffStringsUnified = (
b: string,
options?: DiffOptions,
): string => {
if (a !== b && a.length !== 0 && b.length !== 0) {
if (a !== b && a.length > 0 && b.length > 0) {
const isMultiline = a.includes('\n') || b.includes('\n');

// getAlignedDiffs assumes that a newline was appended to the strings.
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-docblock/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function print({
head +
line +
(comments ? printedComments : '') +
(comments && keys.length ? start + line : '') +
(comments && keys.length > 0 ? start + line : '') +
printedObject +
tail
);
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-fake-timers/src/legacyFakeTimers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ export default class FakeTimers<TimerRef = unknown> {
// Some of the immediate calls could be enqueued
// during the previous handling of the timers, we should
// run them as well.
if (this._immediates.length) {
if (this._immediates.length > 0) {
this.runAllImmediates();
}

if (this._ticks.length) {
if (this._ticks.length > 0) {
this.runAllTicks();
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/crawlers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function findNative(
args.push('-type', 'f');
}

if (extensions.length) {
if (extensions.length > 0) {
args.push('(');
}
extensions.forEach((ext, index) => {
Expand All @@ -154,7 +154,7 @@ function findNative(
args.push('-iname');
args.push(`*.${ext}`);
});
if (extensions.length) {
if (extensions.length > 0) {
args.push(')');
}

Expand Down
Loading

0 comments on commit 5fc7262

Please sign in to comment.