Skip to content

Commit

Permalink
Ignore test references
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhafiz committed Mar 27, 2023
1 parent 9090cb3 commit 17563df
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions scripts/buildTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,38 +118,43 @@ packagesWithTs.forEach(({packageDir, pkg}) => {
cwd: packageDir,
});

const testUtilsReferences = tsConfigPaths.filter(tsConfigPath => {
const tsConfig = JSON.parse(
stripJsonComments(fs.readFileSync(tsConfigPath, 'utf8')),
);
const references = tsConfig.references.map(({path}) => path);

return references.some(reference => /test-utils$/.test(reference));
});

if (hasJestTestUtils && testUtilsReferences.length === 0) {
throw new Error(
chalk.red(
`Package '${
pkg.name
}' declares '@jest/test-utils' as dev dependency, but it is not referenced in:\n\n${tsConfigPaths.join(
'\n',
)}`,
),
);
}

if (!hasJestTestUtils && testUtilsReferences.length > 0) {
throw new Error(
chalk.red(
`Package '${
pkg.name
}' does not declare '@jest/test-utils' as dev dependency, but it is referenced in:\n\n${testUtilsReferences.join(
'\n',
)}`,
),
);
}
// RWX-PATCH: we don't care about tsconfigs equating to the package
// dependencies.
// Since we overwrite the package dependencies with rwx-exposed versions
// anyway, and this is only relevant in dev builds, simply ignore the
// check.
// const testUtilsReferences = tsConfigPaths.filter(tsConfigPath => {
// const tsConfig = JSON.parse(
// stripJsonComments(fs.readFileSync(tsConfigPath, 'utf8')),
// );
// const references = tsConfig.references.map(({path}) => path);

// return references.some(reference => /test-utils$/.test(reference));
// });

// if (hasJestTestUtils && testUtilsReferences.length === 0) {
// throw new Error(
// chalk.red(
// `Package '${
// pkg.name
// }' declares '@jest/test-utils' as dev dependency, but it is not referenced in:\n\n${tsConfigPaths.join(
// '\n',
// )}`,
// ),
// );
// }

// if (!hasJestTestUtils && testUtilsReferences.length > 0) {
// throw new Error(
// chalk.red(
// `Package '${
// pkg.name
// }' does not declare '@jest/test-utils' as dev dependency, but it is referenced in:\n\n${testUtilsReferences.join(
// '\n',
// )}`,
// ),
// );
// }
});

const args = [
Expand Down

0 comments on commit 17563df

Please sign in to comment.