Skip to content

Commit

Permalink
chore: fix new tap test warning in DangerJS
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjeffos committed Jun 1, 2021
1 parent 254e67e commit 81fb744
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,19 @@ if (danger.github && danger.github.pr) {
);
}

// `.spec.ts` is always used for Jest tests
// `.test.ts` is normally used for Tap tests and but there are also `.spec.ts` files which are used be Tap tests in test/acceptance.
// either way, we should warn about new `.test.ts` or `.spec.ts` files being created outside the `/test/jest` folder
const newTestFiles = danger.git.created_files.filter((f) => {
const inTestFolder = f.startsWith('test/');
const inLegacyAcceptanceTestsFolder = f.includes('test/acceptance/');
const testFilenameLooksLikeJest = f.includes('.spec.ts');
return (
inTestFolder &&
!inLegacyAcceptanceTestsFolder &&
!testFilenameLooksLikeJest
);
const isATestFile = f.includes('.test.ts') || f.includes('.spec.ts');
const inJestFolder = f.startsWith('test/jest/');
return inTestFolder && isATestFile && !inJestFolder;
});

if (newTestFiles.length) {
const joinedFileList = newTestFiles.map((f) => '- `' + f + '`').join('\n');
const msg = `Looks like you added a new Tap test. Consider making it a Jest test instead. See files like \`test/*.spec.ts\` for examples. Files found:\n${joinedFileList}`;
const msg = `Looks like you added a new Tap test. Consider making it a Jest test instead. See files in \`test/jest/(unit|system|acceptance)\` for examples. Files found:\n${joinedFileList}`;
warn(msg);
}

Expand Down

0 comments on commit 81fb744

Please sign in to comment.