Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 96c1fd6

Browse files
author
David Bushong
committed
test: properly test PR template code
1 parent d68474d commit 96c1fd6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

test/pr.test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const addHooks = require('./test-common');
99
const verifySetup = require('../lib/setup');
1010
const { action: startAction } = require('../lib/commands/start');
1111
const { action: prAction } = require('../lib/commands/pr');
12+
const { writeFileSync, mkdirSync } = require('fs');
1213

1314
function extractURL(logs) {
1415
return URL.parse(logs.match(/^Opening (https:\S+)/m)[1], true);
@@ -64,21 +65,34 @@ describe('pr', () => {
6465
});
6566

6667
it('respects the contents of a PULL_REQUEST_TEMPLATE', async () => {
68+
writeFileSync('PULL_REQUEST_TEMPLATE.md', 'Important stuff');
6769
const url = await setupForPR(t, ['feat: use a PR template']);
6870
assert.include(
6971
'contents of a PULL_REQUEST_TEMPLATE.md file',
70-
"Please ensure you adequately describe both the problem you're solving for",
72+
'Important stuff',
73+
url.query.body
74+
);
75+
});
76+
77+
it('respects the contents of a .github/pull_request_template', async () => {
78+
mkdirSync('.github');
79+
writeFileSync('.github/pull_request_template.md', 'Other stuff');
80+
const url = await setupForPR(t, ['feat: use a PR template']);
81+
assert.include(
82+
'contents of a pull_request_template.md file',
83+
'Other stuff',
7184
url.query.body
7285
);
7386
});
7487

7588
it('optionally ignores PULL_REQUEST_TEMPLATE', async () => {
89+
writeFileSync('PULL_REQUEST_TEMPLATE.md', 'Important stuff');
7690
const url = await setupForPR(t, ['feat: use a PR template'], {
7791
ignorePrTemplate: true,
7892
});
7993
assert.notInclude(
8094
'contents of the PULL REQUEST TEMPLATE are not present',
81-
"Please ensure you adequately describe both the problem you're solving for",
95+
'Important stuff',
8296
url.query.body
8397
);
8498
});

test/test-common.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,23 @@ function addHooks(main = 'master') {
122122
};
123123

124124
let savedUser;
125+
let savedDir;
125126

126127
beforeEach('setup git dir', async () => {
127128
savedUser = process.env.USER;
129+
savedDir = process.cwd();
128130
process.env.USER = FAKE_USER;
129131
[t.ghDir, t.ghGit] = await setupGitHubDir();
130132
[t.localDir, t.git] = await setupLocalDir(t.ghDir, t.ghGit, main);
131133
[t.localDir2, t.git2] = await setupLocalDir2(t.ghDir);
132134
[t.forkDir, t.gitFork] = await setupForkDir(t.ghDir);
133135
t.logged = '';
136+
process.chdir(t.localDir);
134137
});
135138

136139
afterEach(() => {
137140
process.env.USER = savedUser;
141+
process.chdir(savedDir);
138142
delete t.forceBool;
139143
return Promise.all(
140144
[t.ghDir, t.localDir, t.localDir2, t.forkDir].map(dir =>

0 commit comments

Comments
 (0)