Skip to content

Commit fce166c

Browse files
committed
simplifying the markup test
1 parent 4c35852 commit fce166c

14 files changed

+75
-248
lines changed

lib/markup.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
export default function (doc) {
2-
console.log('transforming markup for document');
32
for (const data of doc.data) {
43
const { id, attributes } = data;
5-
console.log(`\tGenerating markup for ${id}`);
64

75
try {
86
const description = attributes.description;
@@ -11,20 +9,16 @@ export default function (doc) {
119
attributes.description = fixFilename(description);
1210
}
1311

14-
// console.log('\tcompleted highlighting')
15-
1612
replaceDescriptionFor(attributes.methods);
1713
replaceDescriptionFor(attributes.properties);
1814
replaceDescriptionFor(attributes.events);
19-
// console.log(`\tMarkup Generated for ${id}\n`)
2015
} catch (e) {
2116
console.log(`Error generating markup for ${id}`);
2217
console.log(e);
2318
process.exit(1);
2419
}
2520
}
2621

27-
console.log('completed markup transformation for document');
2822
return doc;
2923
}
3024

@@ -39,7 +33,7 @@ function replaceDescriptionFor(items) {
3933
}
4034
}
4135

42-
function fixFilename(description) {
36+
export function fixFilename(description) {
4337
if (description) {
4438
description = description
4539
.replaceAll(/```([^\n]+)\.(js|hbs|ts)\n/g, '```$2 {data-filename=$1.$2}\n')

test/markup-test.js

+12-51
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,19 @@
1-
import markup from '../lib/markup.js';
1+
import { fixFilename } from '../lib/markup.js';
22
import { assert } from 'chai';
3-
import fs from 'fs';
3+
import fsExtra from 'fs-extra';
4+
import { join } from 'path';
45

5-
function desc(path) {
6-
return {
7-
id: Date.now(),
8-
attributes: {
9-
description: fs.readFileSync(`./test/mocks/description/${path}.md`, 'utf-8'),
10-
methods: [],
11-
properties: [],
12-
events: [],
13-
},
14-
};
15-
}
6+
const { readFileSync, readdirSync } = fsExtra;
167

17-
function mark(path) {
18-
let data = [desc(path)];
19-
let result = markup({ data });
20-
let content = result.data[0].attributes.description;
21-
maybeWrite(content, path);
22-
return content;
23-
}
24-
25-
function maybeWrite(content, path) {
26-
const fsPath = `./test/mocks/description/${path}.html`;
27-
if (fs.existsSync(fsPath)) {
28-
return;
29-
}
30-
fs.writeFileSync(fsPath, content, 'utf-8');
31-
}
32-
33-
function snapshot(path) {
34-
const fsPath = `./test/mocks/description/${path}.html`;
35-
return fs.readFileSync(fsPath, 'utf8');
36-
}
8+
const inputFiles = readdirSync('./test/mocks/input');
379

3810
describe('markup', () => {
39-
it('render correct syntax for handlebars with title', function () {
40-
const caseName = 'handlebars-title';
41-
assert.equal(mark(caseName), snapshot(caseName));
42-
});
11+
for (let file of inputFiles) {
12+
it(`render correct syntax for ${file}`, function () {
13+
const inputFile = readFileSync(join('./test/mocks/input', file), 'utf-8');
14+
const outputFile = readFileSync(join('./test/mocks/output', file), 'utf-8');
4315

44-
it('render correct syntax for handlebars without title', function () {
45-
const caseName = 'handlebars';
46-
assert.equal(mark(caseName), snapshot(caseName));
47-
});
48-
49-
it('render correct syntax for javascript with title', function () {
50-
const caseName = 'javascript-title';
51-
assert.equal(mark(caseName), snapshot(caseName));
52-
});
53-
54-
it('render correct syntax for javascript without title', function () {
55-
const caseName = 'javascript';
56-
assert.equal(mark(caseName), snapshot(caseName));
57-
});
16+
assert.equal(fixFilename(inputFile), outputFile);
17+
});
18+
}
5819
});

test/mocks/description/handlebars-title.html

-65
This file was deleted.

test/mocks/description/handlebars.html

-60
This file was deleted.

test/mocks/description/javascript-title.html

-35
This file was deleted.

test/mocks/description/javascript.html

-30
This file was deleted.
File renamed without changes.
File renamed without changes.

test/mocks/output/handlebars-title.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
```handlebars {data-filename=app/components/person-profile.hbs}
2+
<h1>{{person.title}}</h1>
3+
{{! Executed in the component's context. }}
4+
{{yield}} {{! block contents }}
5+
```
6+
If you want to customize the component, in order to
7+
handle events or actions, you implement a subclass
8+
of `Ember.Component` named after the name of the
9+
component.
10+
For example, you could implement the action
11+
`hello` for the `person-profile` component:
12+
```js {data-filename=app/components/person-profile.js}
13+
import Ember from 'ember';
14+
export default Ember.Component.extend({
15+
actions: {
16+
hello(name) {
17+
console.log("Hello", name);
18+
}
19+
}
20+
});
21+
```

test/mocks/output/handlebars.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
```handlebars
2+
<h1>{{person.title}}</h1>
3+
{{! Executed in the component's context. }}
4+
{{yield}} {{! block contents }}
5+
```
6+
If you want to customize the component, in order to
7+
handle events or actions, you implement a subclass
8+
of `Ember.Component` named after the name of the
9+
component.
10+
For example, you could implement the action
11+
`hello` for the `person-profile` component:
12+
```js {data-filename=app/components/person-profile.js}
13+
import Ember from 'ember';
14+
export default Ember.Component.extend({
15+
actions: {
16+
hello(name) {
17+
console.log("Hello", name);
18+
}
19+
}
20+
});
21+
```

test/mocks/output/javascript-title.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
```js {data-filename=app/routes/articles.js}
2+
import Route from '@ember/routing/route';
3+
export default class ArticlesRoute extends Route {
4+
resetController(controller, isExiting, transition) {
5+
if (isExiting && transition.targetName !== 'error') {
6+
controller.set('page', 1);
7+
}
8+
}
9+
}
10+
```

test/mocks/output/javascript.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
```js
2+
import Route from '@ember/routing/route';
3+
export default class ArticlesRoute extends Route {
4+
resetController(controller, isExiting, transition) {
5+
if (isExiting && transition.targetName !== 'error') {
6+
controller.set('page', 1);
7+
}
8+
}
9+
}
10+
```

0 commit comments

Comments
 (0)