-
Notifications
You must be signed in to change notification settings - Fork 13
/
spec.js
78 lines (64 loc) · 2.08 KB
/
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
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
const {
readJsonSync,
readFileSync,
} = require('fs-extra');
const packageJson = require('../../package.json');
const editor = require('./');
describe('edit-package', () => {
afterEach(async () => {
await editor.reset();
});
it('reads the package data', async () => {
expect(await editor.read()).to.deep.equal(packageJson);
});
it('should edit package.json file', async () => {
await editor.write({ name: 'NOT_THE_PACKAGE_NAME' });
expect(readJsonSync('package.json').name).to.equal('NOT_THE_PACKAGE_NAME');
});
it('should merge with existing package.json info', async () => {
await editor.write({ name: 'NOT_THE_PACKAGE_NAME' });
expect(readJsonSync('package.json').version).to.equal(packageJson.version);
});
it('reset restores original package.json', async () => {
await editor.write({ name: 'NOT_THE_PACKAGE_NAME', newkey: 'THIS WAS NOT HERE BEFORE' });
await editor.reset();
const {
name,
newkey,
} = readJsonSync('package.json');
expect(name).not.to.equal('NOT_THE_PACKAGE_NAME');
expect(name).to.equal(packageJson.name);
expect(newkey).to.be.undefined;
});
it('continues from saved package file', async () => {
await editor.write({ name: 'HAIM MISPARAIM' });
await editor.write({ version: '0.0.0-test' });
expect(readJsonSync('package.json').name).to.equal('HAIM MISPARAIM');
});
it('edits nested attributes', async () => {
await editor.write({
publishConfig: {
tag: 'next',
'tag-version-prefix': 'next-tag',
},
});
await editor.write({
publishConfig: {
tag: 'after-next',
},
});
expect(readJsonSync('package.json').publishConfig['tag-version-prefix']).to.equal('next-tag');
});
it('creates a beautified result', async () => {
const contents = readFileSync('package.json').toString();
expect(contents).to.include('\n');
// new line after the opening {
expect(contents[1]).to.equal('\n');
// has indentation
const line = contents.split('\n')[1];
expect(line).to.endWith(line.trim());
expect(line).to.not.equal(line.trim());
// space after colon
expect(contents.split('":')[1][0]).to.equal(' ');
});
});