-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent-cli.test.ts
More file actions
93 lines (73 loc) · 2.95 KB
/
component-cli.test.ts
File metadata and controls
93 lines (73 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { IFs, vol } from 'memfs';
import * as _fs from 'fs/promises';
import { templateVariableDefinitions, directoryStructure } from './util';
import addComponent from './methods/add';
import removeComponent from 'methods/remove';
import renameComponent from 'methods/rename';
jest.doMock( 'fs' );
jest.doMock( 'fs/promises' );
/**
* Transforms into array of arrays for consumption by `it.each()`, e.g.
*
* [
* ['#Component#', 'Pascal Case, leading underscore for subcomponents', 'Widget', '_WidgetSubwidget'],
* ['#COMPONENT#', 'Constant Case, leading underscore for subcomponents', 'WIDGET', '_WIDGET_SUBWIDGET'],
* ]
*/
const templateVariableTestParameters = templateVariableDefinitions.map(
( definition ) => Object.values( definition ).map(
( value ) => typeof value === 'string' ? value : Object.values( value ),
).flat(),
);
const root = 'Widget';
const sub = 'Subwidget';
const fs = _fs as unknown as IFs['promises'];
describe( 'Component CLI', () => {
// beforeAll( () => {
// vol.fromJSON( directoryStructure );
// } );
describe( 'Add', () => {
it( 'Creates a new component at the root level', async () => {
await addComponent( root );
const lstat = await fs.lstat( './src/components/Widget' );
expect( lstat.isDirectory() ).toBe( true );
} );
it.todo( 'Creates a new subcomponent' );
it.todo( 'Throws an error if attempting to create a nested subcomponent' );
describe( 'Variables', () => {
// it( 'Mock file', async () => {
// const filePath = '/file.txt';
// let writeResult;
// let readResult;
// try {
// writeResult = await ( fs as unknown as IFs['promises'] ).writeFile( filePath, 'hello Test' );
// } catch ( error ) {
// console.error( 'write error', error );
// }
// console.log( 'writeResult', writeResult );
// try {
// readResult = await ( fs as unknown as IFs['promises'] ).readFile( filePath, 'utf8' );
// } catch ( error ) {
// console.error( 'read error' );
// }
// console.log( 'readResult', readResult );
// } );
// it.each( templateVariableTestParameters )( '%s (%s)', ( name, description, rootOutput, subOutput ) => {
// console.log( 'name', name );
// console.log( 'description', description );
// console.log( 'rootOutput', rootOutput );
// console.log( 'subOutput', subOutput );
// } );
} );
} );
describe( 'Remove', () => {
it.todo( 'Deletes an existing component' );
} );
describe( 'Rename', () => {
it.todo( 'Renames a root-level component to a root-level component' );
it.todo( 'Renames and moves a root-level component to a subcomponent' );
it.todo( 'Renames a subcomponent to a subcomponent with the same parent' );
it.todo( 'Renames a subcomponent to a subcomponent with a different parent' );
it.todo( 'Renames a subcomponent to a root-level component' );
} );
} );