Skip to content

Commit

Permalink
chore(test) Some more work on test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
jeromesimeon committed Oct 23, 2019
1 parent ac1f13c commit b04388d
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 47 deletions.
3 changes: 2 additions & 1 deletion packages/markdown-cicero/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = {
coverageReporters: [
'json',
'text',
'lcov'
'lcov',
'html'
],

// An object that configures minimum threshold enforcement for coverage results
Expand Down
74 changes: 31 additions & 43 deletions packages/markdown-cli/lib/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,7 @@ class Commands {
}

let argExists = true;
if (Array.isArray(argv[argName])) {
// All files should exist
for (let i = 0; i < argv[argName].length; i++) {
if (Fs.existsSync(argv[argName][i]) && argExists) {
argExists = true;
} else {
argExists = false;
}
}
} else {
// This file should exist
argExists = Fs.existsSync(argv[argName]);
}
argExists = Fs.existsSync(argv[argName]);

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

if (cicero) {
result = ciceroMark.fromCommonMark(result, 'json');
if(verbose) {
console.log('=== CiceroMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CiceroMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
}
else if (slate) {
result = ciceroMark.fromCommonMark(result, 'json');
if(verbose) {
console.log('=== CiceroMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CiceroMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
result = slateMark.fromCiceroMark(result);
if(verbose) {
console.log('=== Slate DOM ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== Slate DOM ===');
Logger.info(JSON.stringify(result, null, 4));
}
} else if (html) {
result = ciceroMark.fromCommonMark(result, 'json');
if(verbose) {
console.log('=== CiceroMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CiceroMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
result = htmlMark.toHtml(result);
}
Expand Down Expand Up @@ -194,21 +182,21 @@ class Commands {
ciceroOptions.wrapVariables = noWrap ? false : true;
result = ciceroMark.toCommonMark(result, ciceroOptions);
if(verbose) {
console.log('=== CommonMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CommonMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
} else if (slate) {
result = slateMark.toCiceroMark(result, 'json');
if(verbose) {
console.log('=== CiceroMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CiceroMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
const ciceroOptions = {};
ciceroOptions.wrapVariables = noWrap ? false : true;
result = ciceroMark.toCommonMark(result, ciceroOptions);
if(verbose) {
console.log('=== CommonMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CommonMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
} else if (html) {
throw new Error('Cannot roundtrip from HTML');
Expand Down Expand Up @@ -264,27 +252,27 @@ class Commands {
const markdownText = Fs.readFileSync(samplePath, 'utf8');
let result = commonMark.fromMarkdown(markdownText, 'json');
if(verbose) {
console.log('=== CommonMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CommonMark ===');
Logger.info(JSON.stringify(result, null, 4));
}

if (cicero) {
result = ciceroMark.fromCommonMark(result, 'json');
if(verbose) {
console.log('=== CiceroMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CiceroMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
}
else if (slate) {
result = ciceroMark.fromCommonMark(result, 'json');
if(verbose) {
console.log('=== CiceroMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CiceroMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
result = slateMark.fromCiceroMark(result);
if(verbose) {
console.log('=== Slate DOM ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== Slate DOM ===');
Logger.info(JSON.stringify(result, null, 4));
}
}

Expand All @@ -293,21 +281,21 @@ class Commands {
ciceroOptions.wrapVariables = noWrap ? false : true;
result = ciceroMark.toCommonMark(result, ciceroOptions);
if(verbose) {
console.log('=== CommonMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CommonMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
} else if (slate) {
result = slateMark.toCiceroMark(result, 'json');
if(verbose) {
console.log('=== CiceroMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CiceroMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
const ciceroOptions = {};
ciceroOptions.wrapVariables = noWrap ? false : true;
result = ciceroMark.toCommonMark(result, ciceroOptions);
if(verbose) {
console.log('=== CommonMark ===');
console.log(JSON.stringify(result, null, 4));
Logger.info('=== CommonMark ===');
Logger.info(JSON.stringify(result, null, 4));
}
} else if (html) {
throw new Error('Cannot roundtrip from HTML');
Expand Down
64 changes: 64 additions & 0 deletions packages/markdown-cli/test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,40 @@ function normalizeNLs(input) {
return text;
}

describe('#validateParseArgs', () => {
it('no args specified', () => {
process.chdir(path.resolve(__dirname, 'data/'));
const args = Commands.validateParseArgs({
_: ['parse'],
});
args.sample.should.match(/sample.md$/);
});
it('no args specified (verbose)', () => {
process.chdir(path.resolve(__dirname, 'data/'));
const args = Commands.validateParseArgs({
_: ['parse'],
verbose: true
});
args.sample.should.match(/sample.md$/);
});
it('all args specified', () => {
process.chdir(path.resolve(__dirname, 'data/'));
const args = Commands.validateParseArgs({
_: ['parse'],
template: './',
sample: 'sample.md'
});
args.sample.should.match(/sample.md$/);
});
it('bad sample.md', () => {
process.chdir(path.resolve(__dirname, 'data/'));
(() => Commands.validateParseArgs({
_: ['parse'],
sample: 'sample_en.md'
})).should.throw('A sample.md file is required. Try the --sample flag or create a sample.md.');
});
});

describe('markdown-cli', () => {
const sample = path.resolve(__dirname, 'data', 'acceptance.md');
const sampleExpected = path.resolve(__dirname, 'data', 'acceptance.json');
Expand All @@ -55,6 +89,16 @@ describe('markdown-cli', () => {
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedJson));
});

it('should parse a markdown file to CommonMark (verbose)', async () => {
const options = {};
options.cicero = false;
options.slate = false;
options.noWrap = true;
options.verbose = true;
const result = await Commands.parse(sample, null, options);
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedJson));
});

it('should parse a markdown file to CiceroMark', async () => {
const options = {};
options.cicero = true;
Expand All @@ -64,6 +108,16 @@ describe('markdown-cli', () => {
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedCiceroMarkJson));
});

it('should parse a markdown file to CiceroMark (verbose)', async () => {
const options = {};
options.cicero = true;
options.slate = false;
options.noWrap = true;
options.verbose = true;
const result = await Commands.parse(sample, null, options);
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedCiceroMarkJson));
});

it('should parse a markdown file to Slate', async () => {
const options = {};
options.cicero = false;
Expand All @@ -72,6 +126,16 @@ describe('markdown-cli', () => {
const result = await Commands.parse(sample, null, options);
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedSlateJson));
});

it('should parse a markdown file to Slate (verbose)', async () => {
const options = {};
options.cicero = false;
options.slate = true;
options.noWrap = true;
options.verbose = true;
const result = await Commands.parse(sample, null, options);
JSON.stringify(JSON.parse(result)).should.eql(JSON.stringify(sampleExpectedSlateJson));
});
});

describe('#draft', () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/markdown-cli/test/data/sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Heading

And below is a **clause**.

``` <clause src="ap://[email protected]#721d1aa0999a5d278653e211ae2a64b75fdd8ca6fa1f34255533c942404c5c1f" clauseid="479adbb4-dc55-4d1a-ab12-b6c5e16900c0"/>
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"/>.
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"/>.
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.
```
3 changes: 2 additions & 1 deletion packages/markdown-common/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = {
coverageReporters: [
'json',
'text',
'lcov'
'lcov',
'html'
],

// An object that configures minimum threshold enforcement for coverage results
Expand Down
3 changes: 2 additions & 1 deletion packages/markdown-html/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = {
coverageReporters: [
'json',
'text',
'lcov'
'lcov',
'html'
],

// An object that configures minimum threshold enforcement for coverage results
Expand Down
3 changes: 2 additions & 1 deletion packages/markdown-slate/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = {
coverageReporters: [
'json',
'text',
'lcov'
'lcov',
'html'
],

// An object that configures minimum threshold enforcement for coverage results
Expand Down

0 comments on commit b04388d

Please sign in to comment.