forked from angular-schule/angular-cli-ghpages
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.spec.ts
More file actions
113 lines (92 loc) · 3.99 KB
/
engine.spec.ts
File metadata and controls
113 lines (92 loc) · 3.99 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { logging } from '@angular-devkit/core';
import * as engine from './engine';
describe('engine', () => {
describe('prepareOptions', () => {
const logger = new logging.NullLogger();
beforeEach(() => {
process.env = {};
});
it('should replace the string GH_TOKEN in the repo url (for backwards compatibility)', async () => {
const options = {
repo: 'https://GH_TOKEN@github.com/organisation/your-repo.git'
};
process.env.GH_TOKEN = 'XXX';
const finalOptions = await engine.prepareOptions(options, logger);
expect(finalOptions.repo).toBe(
'https://XXX@github.com/organisation/your-repo.git'
);
});
// see https://github.com/EdricChan03/rss-reader/commit/837dc10c18bfa453c586bb564a662e7dad1e68ab#r36665276 as an example
it('should be possible to use GH_TOKEN in repo url as a workaround for other tokens (for backwards compatibility)', async () => {
const options = {
repo:
'https://x-access-token:GH_TOKEN@github.com/organisation/your-repo.git'
};
process.env.GH_TOKEN = 'XXX';
const finalOptions = await engine.prepareOptions(options, logger);
expect(finalOptions.repo).toBe(
'https://x-access-token:XXX@github.com/organisation/your-repo.git'
);
});
// ----
it('should also add a personal access token (GH_TOKEN) to the repo url', async () => {
const options = {
repo: 'https://github.com/organisation/your-repo.git'
};
process.env.GH_TOKEN = 'XXX';
const finalOptions = await engine.prepareOptions(options, logger);
expect(finalOptions.repo).toBe(
'https://x-access-token:XXX@github.com/organisation/your-repo.git'
);
});
it('should also add a personal access token (PERSONAL_TOKEN) to the repo url', async () => {
const options = {
repo: 'https://github.com/organisation/your-repo.git'
};
process.env.PERSONAL_TOKEN = 'XXX';
const finalOptions = await engine.prepareOptions(options, logger);
expect(finalOptions.repo).toBe(
'https://x-access-token:XXX@github.com/organisation/your-repo.git'
);
});
it('should also add a installation access token (GITHUB_TOKEN) to the repo url', async () => {
const options = {
repo: 'https://github.com/organisation/your-repo.git'
};
process.env.GITHUB_TOKEN = 'XXX';
const finalOptions = await engine.prepareOptions(options, logger);
expect(finalOptions.repo).toBe(
'https://x-access-token:XXX@github.com/organisation/your-repo.git'
);
});
// NEW in 0.6.2: always discover remote URL (if not set)
// this allows us to inject tokens from environment even if --repo is not set manually
// it uses gh-pages lib directly for this
it('should discover the remote url, if no --repo is set', async () => {
const options = {repo: 'angular-schule/angular-cli-ghpages'};
const finalOptions = await engine.prepareOptions(options, logger);
expect(finalOptions.repo).toMatch(/angular-schule\/angular-cli-ghpages/);
});
});
describe('prepareOptions - handling dotfiles, notfound, and nojekyll', () => {
const logger = new logging.NullLogger();
it('should set dotfiles, notfound, and nojekyll to false when no- flags are given', async () => {
const options = {
noDotfiles: true,
noNotfound: true,
noNojekyll: true
};
const finalOptions = await engine.prepareOptions(options, logger);
expect(finalOptions.dotfiles).toBe(false);
expect(finalOptions.notfound).toBe(false);
expect(finalOptions.nojekyll).toBe(false);
});
it('should set dotfiles, notfound, and nojekyll to true when no- flags are not given', async () => {
const options = {};
const finalOptions = await engine.prepareOptions(options, logger);
expect(finalOptions.dotfiles).toBe(true);
expect(finalOptions.notfound).toBe(true);
expect(finalOptions.nojekyll).toBe(true);
});
});
});