Skip to content

Commit b04388d

Browse files
committed
chore(test) Some more work on test coverage
Signed-off-by: Jerome Simeon <[email protected]>
1 parent ac1f13c commit b04388d

File tree

7 files changed

+114
-47
lines changed

7 files changed

+114
-47
lines changed

packages/markdown-cicero/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ module.exports = {
5151
coverageReporters: [
5252
'json',
5353
'text',
54-
'lcov'
54+
'lcov',
55+
'html'
5556
],
5657

5758
// An object that configures minimum threshold enforcement for coverage results

packages/markdown-cli/lib/Commands.js

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,7 @@ class Commands {
4343
}
4444

4545
let argExists = true;
46-
if (Array.isArray(argv[argName])) {
47-
// All files should exist
48-
for (let i = 0; i < argv[argName].length; i++) {
49-
if (Fs.existsSync(argv[argName][i]) && argExists) {
50-
argExists = true;
51-
} else {
52-
argExists = false;
53-
}
54-
}
55-
} else {
56-
// This file should exist
57-
argExists = Fs.existsSync(argv[argName]);
58-
}
46+
argExists = Fs.existsSync(argv[argName]);
5947

6048
if (!argExists){
6149
throw new Error(`A ${argDefaultName} file is required. Try the --${argName} flag or create a ${argDefaultName}.`);
@@ -108,33 +96,33 @@ class Commands {
10896
const markdownText = Fs.readFileSync(samplePath, 'utf8');
10997
let result = commonMark.fromMarkdown(markdownText, 'json');
11098
if(verbose) {
111-
console.log('=== CommonMark ===');
112-
console.log(JSON.stringify(result, null, 4));
99+
Logger.info('=== CommonMark ===');
100+
Logger.info(JSON.stringify(result, null, 4));
113101
}
114102

115103
if (cicero) {
116104
result = ciceroMark.fromCommonMark(result, 'json');
117105
if(verbose) {
118-
console.log('=== CiceroMark ===');
119-
console.log(JSON.stringify(result, null, 4));
106+
Logger.info('=== CiceroMark ===');
107+
Logger.info(JSON.stringify(result, null, 4));
120108
}
121109
}
122110
else if (slate) {
123111
result = ciceroMark.fromCommonMark(result, 'json');
124112
if(verbose) {
125-
console.log('=== CiceroMark ===');
126-
console.log(JSON.stringify(result, null, 4));
113+
Logger.info('=== CiceroMark ===');
114+
Logger.info(JSON.stringify(result, null, 4));
127115
}
128116
result = slateMark.fromCiceroMark(result);
129117
if(verbose) {
130-
console.log('=== Slate DOM ===');
131-
console.log(JSON.stringify(result, null, 4));
118+
Logger.info('=== Slate DOM ===');
119+
Logger.info(JSON.stringify(result, null, 4));
132120
}
133121
} else if (html) {
134122
result = ciceroMark.fromCommonMark(result, 'json');
135123
if(verbose) {
136-
console.log('=== CiceroMark ===');
137-
console.log(JSON.stringify(result, null, 4));
124+
Logger.info('=== CiceroMark ===');
125+
Logger.info(JSON.stringify(result, null, 4));
138126
}
139127
result = htmlMark.toHtml(result);
140128
}
@@ -194,21 +182,21 @@ class Commands {
194182
ciceroOptions.wrapVariables = noWrap ? false : true;
195183
result = ciceroMark.toCommonMark(result, ciceroOptions);
196184
if(verbose) {
197-
console.log('=== CommonMark ===');
198-
console.log(JSON.stringify(result, null, 4));
185+
Logger.info('=== CommonMark ===');
186+
Logger.info(JSON.stringify(result, null, 4));
199187
}
200188
} else if (slate) {
201189
result = slateMark.toCiceroMark(result, 'json');
202190
if(verbose) {
203-
console.log('=== CiceroMark ===');
204-
console.log(JSON.stringify(result, null, 4));
191+
Logger.info('=== CiceroMark ===');
192+
Logger.info(JSON.stringify(result, null, 4));
205193
}
206194
const ciceroOptions = {};
207195
ciceroOptions.wrapVariables = noWrap ? false : true;
208196
result = ciceroMark.toCommonMark(result, ciceroOptions);
209197
if(verbose) {
210-
console.log('=== CommonMark ===');
211-
console.log(JSON.stringify(result, null, 4));
198+
Logger.info('=== CommonMark ===');
199+
Logger.info(JSON.stringify(result, null, 4));
212200
}
213201
} else if (html) {
214202
throw new Error('Cannot roundtrip from HTML');
@@ -264,27 +252,27 @@ class Commands {
264252
const markdownText = Fs.readFileSync(samplePath, 'utf8');
265253
let result = commonMark.fromMarkdown(markdownText, 'json');
266254
if(verbose) {
267-
console.log('=== CommonMark ===');
268-
console.log(JSON.stringify(result, null, 4));
255+
Logger.info('=== CommonMark ===');
256+
Logger.info(JSON.stringify(result, null, 4));
269257
}
270258

271259
if (cicero) {
272260
result = ciceroMark.fromCommonMark(result, 'json');
273261
if(verbose) {
274-
console.log('=== CiceroMark ===');
275-
console.log(JSON.stringify(result, null, 4));
262+
Logger.info('=== CiceroMark ===');
263+
Logger.info(JSON.stringify(result, null, 4));
276264
}
277265
}
278266
else if (slate) {
279267
result = ciceroMark.fromCommonMark(result, 'json');
280268
if(verbose) {
281-
console.log('=== CiceroMark ===');
282-
console.log(JSON.stringify(result, null, 4));
269+
Logger.info('=== CiceroMark ===');
270+
Logger.info(JSON.stringify(result, null, 4));
283271
}
284272
result = slateMark.fromCiceroMark(result);
285273
if(verbose) {
286-
console.log('=== Slate DOM ===');
287-
console.log(JSON.stringify(result, null, 4));
274+
Logger.info('=== Slate DOM ===');
275+
Logger.info(JSON.stringify(result, null, 4));
288276
}
289277
}
290278

@@ -293,21 +281,21 @@ class Commands {
293281
ciceroOptions.wrapVariables = noWrap ? false : true;
294282
result = ciceroMark.toCommonMark(result, ciceroOptions);
295283
if(verbose) {
296-
console.log('=== CommonMark ===');
297-
console.log(JSON.stringify(result, null, 4));
284+
Logger.info('=== CommonMark ===');
285+
Logger.info(JSON.stringify(result, null, 4));
298286
}
299287
} else if (slate) {
300288
result = slateMark.toCiceroMark(result, 'json');
301289
if(verbose) {
302-
console.log('=== CiceroMark ===');
303-
console.log(JSON.stringify(result, null, 4));
290+
Logger.info('=== CiceroMark ===');
291+
Logger.info(JSON.stringify(result, null, 4));
304292
}
305293
const ciceroOptions = {};
306294
ciceroOptions.wrapVariables = noWrap ? false : true;
307295
result = ciceroMark.toCommonMark(result, ciceroOptions);
308296
if(verbose) {
309-
console.log('=== CommonMark ===');
310-
console.log(JSON.stringify(result, null, 4));
297+
Logger.info('=== CommonMark ===');
298+
Logger.info(JSON.stringify(result, null, 4));
311299
}
312300
} else if (html) {
313301
throw new Error('Cannot roundtrip from HTML');

packages/markdown-cli/test/cli.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ function normalizeNLs(input) {
3535
return text;
3636
}
3737

38+
describe('#validateParseArgs', () => {
39+
it('no args specified', () => {
40+
process.chdir(path.resolve(__dirname, 'data/'));
41+
const args = Commands.validateParseArgs({
42+
_: ['parse'],
43+
});
44+
args.sample.should.match(/sample.md$/);
45+
});
46+
it('no args specified (verbose)', () => {
47+
process.chdir(path.resolve(__dirname, 'data/'));
48+
const args = Commands.validateParseArgs({
49+
_: ['parse'],
50+
verbose: true
51+
});
52+
args.sample.should.match(/sample.md$/);
53+
});
54+
it('all args specified', () => {
55+
process.chdir(path.resolve(__dirname, 'data/'));
56+
const args = Commands.validateParseArgs({
57+
_: ['parse'],
58+
template: './',
59+
sample: 'sample.md'
60+
});
61+
args.sample.should.match(/sample.md$/);
62+
});
63+
it('bad sample.md', () => {
64+
process.chdir(path.resolve(__dirname, 'data/'));
65+
(() => Commands.validateParseArgs({
66+
_: ['parse'],
67+
sample: 'sample_en.md'
68+
})).should.throw('A sample.md file is required. Try the --sample flag or create a sample.md.');
69+
});
70+
});
71+
3872
describe('markdown-cli', () => {
3973
const sample = path.resolve(__dirname, 'data', 'acceptance.md');
4074
const sampleExpected = path.resolve(__dirname, 'data', 'acceptance.json');
@@ -55,6 +89,16 @@ describe('markdown-cli', () => {
5589
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedJson));
5690
});
5791

92+
it('should parse a markdown file to CommonMark (verbose)', async () => {
93+
const options = {};
94+
options.cicero = false;
95+
options.slate = false;
96+
options.noWrap = true;
97+
options.verbose = true;
98+
const result = await Commands.parse(sample, null, options);
99+
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedJson));
100+
});
101+
58102
it('should parse a markdown file to CiceroMark', async () => {
59103
const options = {};
60104
options.cicero = true;
@@ -64,6 +108,16 @@ describe('markdown-cli', () => {
64108
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedCiceroMarkJson));
65109
});
66110

111+
it('should parse a markdown file to CiceroMark (verbose)', async () => {
112+
const options = {};
113+
options.cicero = true;
114+
options.slate = false;
115+
options.noWrap = true;
116+
options.verbose = true;
117+
const result = await Commands.parse(sample, null, options);
118+
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedCiceroMarkJson));
119+
});
120+
67121
it('should parse a markdown file to Slate', async () => {
68122
const options = {};
69123
options.cicero = false;
@@ -72,6 +126,16 @@ describe('markdown-cli', () => {
72126
const result = await Commands.parse(sample, null, options);
73127
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedSlateJson));
74128
});
129+
130+
it('should parse a markdown file to Slate (verbose)', async () => {
131+
const options = {};
132+
options.cicero = false;
133+
options.slate = true;
134+
options.noWrap = true;
135+
options.verbose = true;
136+
const result = await Commands.parse(sample, null, options);
137+
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedSlateJson));
138+
});
75139
});
76140

77141
describe('#draft', () => {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Heading
2+
3+
And below is a **clause**.
4+
5+
``` <clause src="ap://[email protected]#721d1aa0999a5d278653e211ae2a64b75fdd8ca6fa1f34255533c942404c5c1f" clauseid="479adbb4-dc55-4d1a-ab12-b6c5e16900c0"/>
6+
Acceptance of Delivery. <variable id="shipper" value="%22Party%20A%22"/> will be deemed to have completed its delivery obligations if in <variable id="receiver" value="%22Party%20B%22"/>'s opinion, the <variable id="deliverable" value="%22Widgets%22"/> satisfies the Acceptance Criteria, and <variable id="receiver" value="%22Party%20B%22"/> notifies <variable id="shipper" value="%22Party%20A%22"/> in writing that it is accepting the <variable id="deliverable" value="%22Widgets%22"/>.
7+
8+
Inspection and Notice. <variable id="receiver" value="%22Party%20B%22"/> will have <variable id="businessDays" value="10"/> Business Days' to inspect and evaluate the <variable id="deliverable" value="%22Widgets%22"/> on the delivery date before notifying <variable id="shipper" value="%22Party%20A%22"/> that it is either accepting or rejecting the <variable id="deliverable" value="%22Widgets%22"/>.
9+
10+
Acceptance Criteria. The "Acceptance Criteria" are the specifications the <variable id="deliverable" value="%22Widgets%22"/> must meet for the <variable id="shipper" value="%22Party%20A%22"/> to comply with its requirements and obligations under this agreement, detailed in <variable id="attachment" value="%22Attachment%20X%22"/>, attached to this agreement.
11+
```

packages/markdown-common/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ module.exports = {
5151
coverageReporters: [
5252
'json',
5353
'text',
54-
'lcov'
54+
'lcov',
55+
'html'
5556
],
5657

5758
// An object that configures minimum threshold enforcement for coverage results

packages/markdown-html/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ module.exports = {
5151
coverageReporters: [
5252
'json',
5353
'text',
54-
'lcov'
54+
'lcov',
55+
'html'
5556
],
5657

5758
// An object that configures minimum threshold enforcement for coverage results

packages/markdown-slate/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ module.exports = {
5151
coverageReporters: [
5252
'json',
5353
'text',
54-
'lcov'
54+
'lcov',
55+
'html'
5556
],
5657

5758
// An object that configures minimum threshold enforcement for coverage results

0 commit comments

Comments
 (0)