-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpages.spec.js
52 lines (45 loc) · 1.33 KB
/
pages.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const ghpages = require('gh-pages');
const { deployDirectoryToGithubPages } = require('./');
jest.mock('gh-pages');
describe('Github pages', () => {
it('deploys to gh-pages with correct options', async () => {
expect.assertions(2);
mockPublishForCallbackArgument(undefined);
const options = {
token: 'a-token',
owner: 'an-owner',
repo: 'a-repo',
dotfiles: true,
verbose: true,
beforeAdd: './beforeAdd.js',
};
expect(ghpages.publish).not.toBeCalled();
await deployDirectoryToGithubPages('a-directory', options);
expect(ghpages.publish).toBeCalledWith(
'a-directory',
{
add: true,
repo: 'https://[email protected]/an-owner/a-repo.git',
silent: false,
dotfiles: true,
beforeAdd: './beforeAdd.js',
},
expect.any(Function),
);
});
it('throws if deployment to gh-pages fails', async () => {
expect.assertions(1);
mockPublishForCallbackArgument('An error');
const directory = 'a-directory';
try {
await deployDirectoryToGithubPages(directory, {});
} catch (err) {
expect(err.message).toContain('An error');
}
});
function mockPublishForCallbackArgument(argument) {
ghpages.publish.mockImplementation((directory, options, callback) => {
callback(argument);
});
}
});