Skip to content

Commit

Permalink
chore: update dangerfile smoke branch detection
Browse files Browse the repository at this point in the history
  • Loading branch information
JackuB committed Oct 27, 2020
1 parent 7d8af65 commit b0f3d71
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { danger, warn, fail, message } = require('danger');

const MAX_COMMIT_MESSAGE_LENGTH = 72;
const SMOKE_TEST_BRANCH = 'feat/smoke-test';
const SMOKE_TEST_BRANCH = 'smoke/';
const SMOKE_TEST_WORKFLOW_FILE_PATH = '.github/workflows/smoke-tests.yml';

if (danger.github && danger.github.pr) {
Expand Down Expand Up @@ -55,11 +55,15 @@ if (danger.github && danger.github.pr) {
const inTestFolder = f.startsWith('test/');
const inLegacyAcceptanceTestsFolder = f.includes('test/acceptance/');
const testFilenameLooksLikeJest = f.includes('.spec.ts');
return inTestFolder && !inLegacyAcceptanceTestsFolder && !testFilenameLooksLikeJest;
return (
inTestFolder &&
!inLegacyAcceptanceTestsFolder &&
!testFilenameLooksLikeJest
);
});

if (newTestFiles.length) {
const joinedFileList = newTestFiles.map(f => '- `' + f + '`').join("\n");
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}`;
warn(msg);
}
Expand All @@ -70,11 +74,13 @@ if (danger.github && danger.github.pr) {
danger.git.created_files.some((f) => f.startsWith('test/smoke/')) ||
danger.git.modified_files.includes(SMOKE_TEST_WORKFLOW_FILE_PATH);

const isOnSmokeTestBranch = danger.github.pr.head.ref === SMOKE_TEST_BRANCH;
const isOnSmokeTestBranch = danger.github.pr.head.ref.startsWith(
SMOKE_TEST_BRANCH,
);

if (modifiedSmokeTest && !isOnSmokeTestBranch) {
message(
`You are modifying something in test/smoke directory, yet you are not on the branch ${SMOKE_TEST_BRANCH}. You can rename your branch to ${SMOKE_TEST_BRANCH} and Smoke tests will trigger for this PR.`,
`You are modifying something in test/smoke directory, yet you are not on the branch starting with ${SMOKE_TEST_BRANCH}. You can prefix your branch with ${SMOKE_TEST_BRANCH} and Smoke tests will trigger for this PR.`,
);
}
}

0 comments on commit b0f3d71

Please sign in to comment.