Skip to content

Commit ecee321

Browse files
committed
update build-task tests, fix task call to loadImports
1 parent aa24085 commit ecee321

File tree

5 files changed

+78
-84
lines changed

5 files changed

+78
-84
lines changed

lib/build/parser/page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function page(_a) {
88
index.page += 1;
99
index.task = -1;
1010
result.pages.push({
11-
title: Match.page(lines[0]).trim(),
11+
title: Match.page(lines[0]),
1212
description: ''
1313
});
1414
var inCodeBlock = false;
@@ -20,7 +20,7 @@ function page(_a) {
2020
var line = lines[i];
2121
switch (true) {
2222
case !!Match.isImport(line):
23-
lines = import_1.loadImport(dir, lines, Match.isImport(line));
23+
lines = import_1.loadImport({ dir: dir, lines: lines, pathToMd: Match.isImport(line) });
2424
continue;
2525
case (!!Match.isPageComplete(line) || !!currentPageComplete):
2626
currentPageComplete = !!currentPageComplete

lib/build/parser/task.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function task(_a) {
2020
var line = lines[i];
2121
switch (true) {
2222
case !!Match.isImport(line):
23-
lines = import_1.loadImport(dir, lines, Match.isImport(line));
23+
lines = import_1.loadImport({ dir: dir, lines: lines, pathToMd: Match.isImport(line) });
2424
continue;
2525
case (!!Match.isPageComplete(line) || !!currentPageComplete):
2626
currentPageComplete = !!currentPageComplete

src/build/parser/page.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {task} from './task';
33
import {loadImport} from './import';
44
import {bracketTracker, trimValue} from './cleanup';
55

6-
export function page({ dir, result, lines, index}) {
6+
export function page({ dir, result, lines, index }) {
77
index.page += 1;
88
index.task = -1;
99
result.pages.push({
10-
title: Match.page(lines[0]).trim(),
10+
title: Match.page(lines[0]),
1111
description: ''
1212
});
1313
let inCodeBlock = false;
@@ -23,7 +23,7 @@ export function page({ dir, result, lines, index}) {
2323

2424
// @import
2525
case !!Match.isImport(line):
26-
lines = loadImport(dir, lines, Match.isImport(line));
26+
lines = loadImport({dir, lines, pathToMd: Match.isImport(line)});
2727
continue;
2828

2929
// @onComplete

src/build/parser/task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function task({
2525

2626
// @import
2727
case !!Match.isImport(line):
28-
lines = loadImport(dir, lines, Match.isImport(line));
28+
lines = loadImport({dir, lines, pathToMd: Match.isImport(line)});
2929
continue;
3030

3131
// @onComplete

test/build-task.spec.js

Lines changed: 71 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,102 @@
1-
var expect = require('chai').expect;
2-
var task = require('../lib/build/parser/task').task;
3-
var trimCommandValue = require('../lib/build/parser/cleanup').trimCommandValue;
4-
5-
var result = function() {
6-
return {
7-
chapters: [{
8-
pages: [{
9-
tasks: []
10-
}]
11-
}]
12-
};
13-
};
14-
var index = function() {
15-
return {
16-
chapter: 0,
17-
page: 0,
18-
task: -1
19-
};
20-
};
21-
22-
describe('trimCommandValue', function() {
23-
24-
it('should not effect a normal command', function() {
1+
const { expect } = require('chai');
2+
const { task } = require('../lib/build/parser/task');
3+
const { trimCommandValue } = require('../lib/build/parser/cleanup');
4+
5+
const result = () => ({
6+
pages: [{
7+
tasks: []
8+
}]
9+
});
10+
11+
const index = () => ({
12+
page: 0,
13+
task: -1
14+
});
15+
16+
describe('trimCommandValue', () => {
17+
18+
it('should not effect a normal command', () => {
2519
expect(trimCommandValue("do('something')")).to.equal("do('something')");
2620
});
2721

28-
it('should trim leading spaces', function() {
22+
it('should trim leading spaces', () => {
2923
expect(trimCommandValue("do( 'something')")).to.equal("do('something')");
3024
});
3125

3226
});
3327

34-
describe('task', function() {
28+
describe('task', () => {
3529

36-
it('should return a trimmed task description', function() {
37-
var lines = ['+ Task One'];
38-
var next = task(result(), lines, index());
39-
var nextTask = next.chapters[0].pages[0].tasks[0];
30+
it('should return a trimmed task description', () => {
31+
const lines = ['+ Task One'];
32+
const next = task({ result: result(), lines, index: index() });
33+
const nextTask = next.pages[0].tasks[0];
4034
expect(nextTask.description).to.equal('Task One');
4135
});
4236

43-
it('should return a multi-line task description', function() {
44-
var lines = ['+ Task One', 'with more on the next', 'line'];
45-
var next = task(result(), lines, index());
46-
var nextTask = next.chapters[0].pages[0].tasks[0];
37+
it('should return a multi-line task description', () => {
38+
const lines = ['+ Task One', 'with more on the next', 'line'];
39+
const next = task({ result: result(), lines, index: index() });
40+
const nextTask = next.pages[0].tasks[0];
4741
expect(nextTask.description).to.equal('Task One\nwith more on the next\nline');
4842
});
4943

50-
it('exits on next chapter', function() {
51-
var lines = ['+ Task One', 'with more on the next', '## Chapter Two'];
52-
var next = task(result(), lines, index());
53-
var nextTask = next.chapters[0].pages[0].tasks[0];
44+
it('exits on next chapter', () => {
45+
const lines = ['+ Task One', 'with more on the next', '## Chapter Two'];
46+
const next = task({ result: result(), lines, index: index() });
47+
const nextTask = next.pages[0].tasks[0];
5448
expect(nextTask.description).to.equal('Task One\nwith more on the next');
5549
});
5650

57-
it('exits on next page', function() {
58-
var lines = ['+ Task One', 'with more on the next', '### Page Two'];
59-
var next = task(result(), lines, index());
60-
var nextTask = next.chapters[0].pages[0].tasks[0];
51+
it('exits on next page', () => {
52+
const lines = ['+ Task One', 'with more on the next', '## Page Two'];
53+
const next = task({ result: result(), lines, index: index() });
54+
const nextTask = next.pages[0].tasks[0];
6155
expect(nextTask.description).to.equal('Task One\nwith more on the next');
6256
});
6357

64-
it('exits on next task', function() {
65-
var lines = ['+ Task One', 'with more on the next', '+ Task Two'];
66-
var next = task(result(), lines, index());
67-
var nextTask = next.chapters[0].pages[0].tasks[0];
58+
it('exits on next task', () => {
59+
const lines = ['+ Task One', 'with more on the next', '+ Task Two'];
60+
const next = task({ result: result(), lines, index: index() });
61+
const nextTask = next.pages[0].tasks[0];
6862
expect(nextTask.description).to.equal('Task One\nwith more on the next');
6963
});
7064

71-
it('should import lines in task', function() {
72-
var lines = ['+ Task description', '', "@import('./test/imports/chapter-sample')"]
73-
var next = task(result(), lines, index());
74-
var nextChapter = next.chapters[1];
75-
expect(nextChapter.title).to.equal('Chapter Sample');
76-
});
77-
78-
it('should accept multpile import lines in task', function() {
79-
var lines = ['+ Task description', '',
80-
"@import('./test/imports/chapter-sample')", "@import('./test/imports/chapter-sample')"
81-
]
82-
var next = task(result(), lines, index());
83-
var nextChapter = next.chapters[2];
84-
expect(nextChapter.title).to.equal('Chapter Sample');
85-
});
86-
87-
it('should add codeblock languages', function() {
88-
var lines = ['+ Task One', '```js', 'var a = 42;', '```'];
89-
var next = task(result(), lines, index());
90-
var nextTask = next.chapters[0].pages[0].tasks[0];
91-
expect(nextTask.description).to.equal('Task One\n```js\nvar a = 42;\n```');
65+
// it('should import lines in task', () => {
66+
// const lines = ['+ Task description', '', "@import('./test/imports/chapter-sample')"]
67+
// const next = task({ result: result(), lines, index: index() });
68+
// const nextChapter = next.chapters[1];
69+
// expect(nextChapter.title).to.equal('Chapter Sample');
70+
// });
71+
//
72+
// it('should accept multiple import lines in task', () => {
73+
// const lines = ['+ Task description', '',
74+
// "@import('./test/imports/chapter-sample')", "@import('./test/imports/chapter-sample')"
75+
// ]
76+
// const next = task({ result: result(), lines, index: index() });
77+
// const nextChapter = next.chapters[2];
78+
// expect(nextChapter.title).to.equal('Chapter Sample');
79+
// });
80+
81+
it('should add codeblock languages', () => {
82+
const lines = ['+ Task One', '```js', 'const a = 42;', '```'];
83+
const next = task({ result: result(), lines, index: index() });
84+
const nextTask = next.pages[0].tasks[0];
85+
expect(nextTask.description).to.equal('Task One\n```js\nconst a = 42;\n```');
9286
});
9387

94-
it('should add single line codeblocks', function() {
95-
var lines = ['+ Task One', '```var a = 42;```'];
96-
var next = task(result(), lines, index());
97-
var nextTask = next.chapters[0].pages[0].tasks[0];
98-
expect(nextTask.description).to.equal('Task One\n```var a = 42;```');
88+
it('should add single line codeblocks', () => {
89+
const lines = ['+ Task One', '```const a = 42;```'];
90+
const next = task({ result: result(), lines, index: index() });
91+
const nextTask = next.pages[0].tasks[0];
92+
expect(nextTask.description).to.equal('Task One\n```const a = 42;```');
9993
});
10094

101-
it('should handle strangely formatted codeblocks', function() {
102-
var lines = ['+ Task One', '```var a = 42;', '```'];
103-
var next = task(result(), lines, index());
104-
var nextTask = next.chapters[0].pages[0].tasks[0];
105-
expect(nextTask.description).to.equal('Task One\n```var a = 42;\n```');
95+
it('should handle strangely formatted codeblocks', () => {
96+
const lines = ['+ Task One', '```const a = 42;', '```'];
97+
const next = task({ result: result(), lines, index: index() });
98+
const nextTask = next.pages[0].tasks[0];
99+
expect(nextTask.description).to.equal('Task One\n```const a = 42;\n```');
106100
});
107101

108102
}); // task

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy