-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathcopy.test.ts
More file actions
69 lines (56 loc) · 1.58 KB
/
Copy pathcopy.test.ts
File metadata and controls
69 lines (56 loc) · 1.58 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
import { createEjsRenderer, createStringReplacer } from './copy';
describe('createEjsRenderer', () => {
it('renders typical skuba placeholders', () => {
const input = {
name: '<%- packageName %>',
repository: {
url: 'git+ssh://git@github.com/<%- orgName %>/<%- repoName %>.git',
},
};
const templateData = {
orgName: 'seek-oss',
packageName: 'seek-koala',
repoName: 'koala',
};
const render = createEjsRenderer(templateData);
const output = render(JSON.stringify(input));
expect(JSON.parse(output)).toEqual({
name: 'seek-koala',
repository: {
url: 'git+ssh://git@github.com/seek-oss/koala.git',
},
});
});
});
describe('createStringReplacer', () => {
it('replaces multiple instances of a global pattern', () => {
const input = 'red green blue red green blue red green';
const replace = createStringReplacer([
{
input: new RegExp('green', 'g'),
output: 'yellow',
},
]);
const output = replace(input);
expect(output).toBe('red yellow blue red yellow blue red yellow');
});
it('runs through multiple patterns', () => {
const input = 'red green blue';
const replace = createStringReplacer([
{
input: new RegExp('red', 'g'),
output: 'cyan',
},
{
input: new RegExp('green', 'g'),
output: 'magenta',
},
{
input: new RegExp('blue', 'g'),
output: 'yellow',
},
]);
const output = replace(input);
expect(output).toBe('cyan magenta yellow');
});
});