Skip to content

Commit da89943

Browse files
authored
tests: Restructure test files for documentation (#173)
1 parent 67b96a2 commit da89943

21 files changed

+102
-127
lines changed

Diff for: .README/api/stream/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
`table` package exports `createStream` function used to draw a table and append rows.
44

5-
Parameter:
5+
**Parameter:**
66
- _**config:**_ the same as `table`'s, except `config.columnDefault.width` and `config.columnCount` must be provided.
77

88

Diff for: .README/api/table/columns/index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
##### config.columns
22

3-
Type: `Column[] | { [columnIndex: number]: Column }`\
3+
Type: `Column[] | { [columnIndex: number]: Column }`
4+
45
Column specific configurations.

Diff for: .README/api/table/columns/width.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Type: `number`\
44
Default: the maximum cell widths of the column
55

6-
Column width.
6+
Column width (excluding the paddings).
77

88
```js
99

Diff for: .README/api/table/columns/wrapWord.md

-17
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,6 @@ console.log(table(data, config));
3434

3535
When `wrapWord` is `true`:
3636

37-
```js
38-
const data = [
39-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
40-
];
41-
42-
const config = {
43-
columns: [
44-
{
45-
width: 20,
46-
wrapWord: true
47-
}
48-
]
49-
};
50-
51-
console.log(table(data, config));
52-
```
53-
5437
```
5538
╔══════════════════════╗
5639
║ Lorem ipsum dolor ║

Diff for: README.md

+4-20
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ console.log(table(data, config));
273273
<a name="table-api-table-1-config-columns"></a>
274274
##### config.columns
275275

276-
Type: `Column[] | { [columnIndex: number]: Column }`\
276+
Type: `Column[] | { [columnIndex: number]: Column }`
277+
277278
Column specific configurations.
278279

279280
<a name="table-api-table-1-config-columns-config-columns-width"></a>
@@ -282,7 +283,7 @@ Column specific configurations.
282283
Type: `number`\
283284
Default: the maximum cell widths of the column
284285

285-
Column width.
286+
Column width (excluding the paddings).
286287

287288
```js
288289

@@ -477,23 +478,6 @@ console.log(table(data, config));
477478

478479
When `wrapWord` is `true`:
479480

480-
```js
481-
const data = [
482-
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.']
483-
];
484-
485-
const config = {
486-
columns: [
487-
{
488-
width: 20,
489-
wrapWord: true
490-
}
491-
]
492-
};
493-
494-
console.log(table(data, config));
495-
```
496-
497481
```
498482
╔══════════════════════╗
499483
║ Lorem ipsum dolor ║
@@ -524,7 +508,7 @@ The default configuration for all columns. Column-specific settings will overwri
524508

525509
`table` package exports `createStream` function used to draw a table and append rows.
526510

527-
Parameter:
511+
**Parameter:**
528512
- _**config:**_ the same as `table`'s, except `config.columnDefault.width` and `config.columnCount` must be provided.
529513

530514

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"create-readme": "gitdown ./.README/README.md --output-file ./README.md",
9090
"create-validators": "rm -fr ./src/generated && mkdirp ./src/generated && ajv compile --all-errors --inline-refs=false -s src/schemas/config -s src/schemas/streamConfig -r src/schemas/shared -c ajv-keywords/dist/keywords/typeof -o | js-beautify > ./src/generated/validators.js",
9191
"lint": "eslint --ignore-path .gitignore ./src ./test",
92-
"test": "npm run create-validators && mocha --require ts-node/register ./test/**/*.ts"
92+
"test": "npm run create-validators && mocha --require ts-node/register \"./test/**/*.ts\""
9393
},
9494
"version": "1.0.0"
9595
}

Diff for: test/README/usage/predefinedBorderTemplates.ts renamed to test/README/api/getBorderCharacters.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import {
55
import type {
66
Row,
77
} from '../../../src/types/internal';
8-
import expectTable from './expectTable';
8+
import {
9+
expectTable,
10+
} from '../../utils';
911

10-
describe('README.md usage/predefined_border_templates', () => {
12+
describe('README.md api/getBorderCharacters', () => {
1113
let data: Row[];
1214

1315
before(() => {

Diff for: test/README/usage/streaming.ts renamed to test/README/api/stream/streaming.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
22
createStream,
3-
} from '../../../src';
4-
import expectTable from './expectTable';
3+
} from '../../../../src';
4+
import {
5+
expectTable,
6+
} from '../../../utils';
57

6-
describe('README.md usage/', () => {
8+
describe('README.md api/stream', () => {
79
describe('process.stdout.write', () => {
810
let processStdoutWriteBuffer: string;
911

Diff for: test/README/usage/customBorder.ts renamed to test/README/api/table/border.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
22
table,
3-
} from '../../../src';
4-
import expectTable from './expectTable';
3+
} from '../../../../src';
4+
import {
5+
expectTable,
6+
} from '../../../utils';
57

6-
describe('README.md usage/', () => {
7-
it('usage/custom_border', () => {
8+
describe('README.md api/table', () => {
9+
it('border', () => {
810
const data = [
911
['0A', '0B', '0C'],
1012
['1A', '1B', '1C'],

Diff for: test/README/usage/cellContentAlignment.ts renamed to test/README/api/table/column/alignment.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import type {
22
TableUserConfig,
3-
} from '../../../src';
3+
} from '../../../../../src';
44
import {
55
table,
6-
} from '../../../src';
7-
import expectTable from './expectTable';
6+
} from '../../../../../src';
7+
import {
8+
expectTable,
9+
} from '../../../../utils';
810

9-
describe('README.md usage/', () => {
10-
it('cell_content_alignment', () => {
11+
describe('README.md api/table/columns', () => {
12+
it('/alignment', () => {
1113
const data = [
1214
['0A', '0B', '0C', '0D 0E 0F'],
1315
['1A', '1B', '1C', '1D 1E 1F'],
@@ -26,9 +28,7 @@ describe('README.md usage/', () => {
2628
],
2729
};
2830

29-
const output = table(data, config);
30-
31-
expectTable(output, `
31+
expectTable(table(data, config), `
3232
╔════════════╤════════════╤════════════╤════════════╗
3333
║ 0A │ 0B │ 0C │ 0D 0E 0F ║
3434
╟────────────┼────────────┼────────────┼────────────╢

Diff for: test/README/usage/paddingCellContent.ts renamed to test/README/api/table/column/padding.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
import {
22
table,
3-
} from '../../../src';
4-
import expectTable from './expectTable';
3+
} from '../../../../../src';
4+
import {
5+
expectTable,
6+
} from '../../../../utils';
57

6-
describe('README.md usage/', () => {
7-
it('usage/padding_cell_content', () => {
8+
describe('README.md api/table/columns/', () => {
9+
it('/padding', () => {
810
const data = [
911
['0A', 'AABBCC', '0C'],
1012
['1A', '1B', '1C'],
1113
['2A', '2B', '2C'],
1214
];
1315

1416
const config = {
15-
columns: {
16-
0: {
17+
columns: [
18+
{
1719
paddingLeft: 3,
1820
},
19-
1: {
21+
{
2022
paddingRight: 3,
2123
width: 2,
2224
},
23-
},
25+
],
2426
};
2527

26-
const output = table(data, config);
27-
28-
expectTable(output, `
28+
expectTable(table(data, config), `
2929
╔══════╤══════╤════╗
3030
║ 0A │ AA │ 0C ║
3131
║ │ BB │ ║

Diff for: test/README/usage/textTruncating.ts renamed to test/README/api/table/column/truncate.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import {
22
table,
3-
} from '../../../src';
4-
import expectTable from './expectTable';
3+
} from '../../../../../src';
4+
import {
5+
expectTable,
6+
} from '../../../../utils';
57

6-
describe('README.md usage/', () => {
7-
it('text_truncating', () => {
8+
describe('README.md api/table/column/', () => {
9+
it('/truncate', () => {
810
const data = [
911
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.'],
1012
];
1113

1214
const config = {
13-
columns: {
14-
0: {
15+
columns: [
16+
{
1517
truncate: 100,
1618
width: 20,
1719
},
18-
},
20+
],
1921
};
2022

21-
const output = table(data, config);
22-
23-
expectTable(output, `
23+
expectTable(table(data, config), `
2424
╔══════════════════════╗
2525
║ Lorem ipsum dolor si ║
2626
║ t amet, consectetur ║

Diff for: test/README/usage/columnWidth.ts renamed to test/README/api/table/column/width.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
22
table,
3-
} from '../../../src';
4-
import expectTable from './expectTable';
3+
} from '../../../../../src';
4+
import {
5+
expectTable,
6+
} from '../../../../utils';
57

6-
describe('README.md usage/', () => {
7-
it('column_width', () => {
8+
describe('README.md api/table/columns/', () => {
9+
it('width', () => {
810
const data = [
911
['0A', '0B', '0C'],
1012
['1A', '1B', '1C'],
@@ -19,9 +21,7 @@ describe('README.md usage/', () => {
1921
},
2022
};
2123

22-
const output = table(data, config);
23-
24-
expectTable(output, `
24+
expectTable(table(data, config), `
2525
╔════╤════════════╤════╗
2626
║ 0A │ 0B │ 0C ║
2727
╟────┼────────────┼────╢

Diff for: test/README/usage/textWrapping.ts renamed to test/README/api/table/column/wrapWord.ts

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import {
22
table,
3-
} from '../../../src';
4-
import expectTable from './expectTable';
3+
} from '../../../../../src';
4+
import {
5+
expectTable,
6+
} from '../../../../utils';
57

6-
describe('README.md usage/', () => {
8+
describe('README.md api/table/column/wrapWord', () => {
79
it('text_wrapping (no wrap word)', () => {
810
const data = [
911
['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pulvinar nibh sed mauris convallis dapibus. Nunc venenatis tempus nulla sit amet viverra.'],
1012
];
1113

1214
const config = {
13-
columns: {
14-
0: {
15-
width: 20,
16-
},
17-
},
15+
columns: [{width: 20}],
1816
};
1917

2018
const output = table(data, config);
@@ -39,17 +37,11 @@ describe('README.md usage/', () => {
3937
];
4038

4139
const config = {
42-
columns: {
43-
0: {
44-
width: 20,
45-
wrapWord: true,
46-
},
47-
},
40+
columns: [{width: 20,
41+
wrapWord: true}],
4842
};
4943

50-
const output = table(data, config);
51-
52-
expectTable(output, `
44+
expectTable(table(data, config), `
5345
╔══════════════════════╗
5446
║ Lorem ipsum dolor ║
5547
║ sit amet, ║

Diff for: test/README/usage/drawHorizontalLine.ts renamed to test/README/api/table/drawHorizontalLine.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {
22
table,
3-
} from '../../../src';
3+
} from '../../../../src';
44
import type {
55
TableUserConfig,
6-
} from '../../../src';
7-
import expectTable from './expectTable';
6+
} from '../../../../src';
7+
import {
8+
expectTable,
9+
} from '../../../utils';
810

9-
describe('README.md usage/', () => {
10-
it('usage/draw_horizontal_line', () => {
11+
describe('README.md api/table', () => {
12+
it('drawHorizontalLine', () => {
1113
const data = [
1214
['0A', '0B', '0C'],
1315
['1A', '1B', '1C'],

Diff for: test/README/usage/drawVerticalLine.ts renamed to test/README/api/table/drawVerticalLine.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {
22
table,
3-
} from '../../../src';
3+
} from '../../../../src';
44
import type {
55
TableUserConfig,
6-
} from '../../../src';
7-
import expectTable from './expectTable';
6+
} from '../../../../src';
7+
import {
8+
expectTable,
9+
} from '../../../utils';
810

9-
describe('README.md usage/', () => {
10-
it('usage/draw_vertical_line', () => {
11+
describe('README.md api/table', () => {
12+
it('drawVerticalLine', () => {
1113
const data = [
1214
['0A', '0B', '0C'],
1315
['1A', '1B', '1C'],

0 commit comments

Comments
 (0)