Skip to content

Commit

Permalink
Adapt IR tests to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jan 30, 2019
1 parent 5d31ec5 commit 7d5fe5c
Showing 1 changed file with 50 additions and 20 deletions.
70 changes: 50 additions & 20 deletions packages/docgen/tests/test-get-intermediate-representation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ test( 'IR - undocumented', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( token ) ), [ {
name: 'default',
description: 'Undocumented declaration.',
params: [],
return: [],
tags: [],
} ] );
const tokenOneliner = fs.readFileSync(
Expand All @@ -31,6 +33,8 @@ test( 'IR - undocumented', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenOneliner ) ), [ {
name: 'default',
description: 'Undocumented declaration.',
params: [],
return: [],
tags: [],
} ] );
t.end();
Expand All @@ -44,6 +48,8 @@ test( 'IR - default (JSDoc in export statement)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenClassAnonymous ) ), [ {
name: 'default',
description: 'Class declaration example.',
params: [],
return: [],
tags: [],
} ] );
const tokenClassNamed = fs.readFileSync(
Expand All @@ -53,6 +59,8 @@ test( 'IR - default (JSDoc in export statement)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenClassNamed ) ), [ {
name: 'default',
description: 'Class declaration example.',
params: [],
return: [],
tags: [],
} ] );
const tokenFnAnonymous = fs.readFileSync(
Expand All @@ -62,6 +70,8 @@ test( 'IR - default (JSDoc in export statement)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenFnAnonymous ) ), [ {
name: 'default',
description: 'Function declaration example.',
params: [],
return: [],
tags: [],
} ] );
const tokenFnNamed = fs.readFileSync(
Expand All @@ -71,6 +81,8 @@ test( 'IR - default (JSDoc in export statement)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenFnNamed ) ), [ {
name: 'default',
description: 'Function declaration example.',
params: [],
return: [],
tags: [],
} ] );
const tokenVariable = fs.readFileSync(
Expand All @@ -80,6 +92,8 @@ test( 'IR - default (JSDoc in export statement)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenVariable ) ), [ {
name: 'default',
description: 'Variable declaration example.',
params: [],
return: [],
tags: [],
} ] );
t.end();
Expand All @@ -97,6 +111,8 @@ test( 'IR - default (JSDoc in same file)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( token ), JSON.parse( ast ) ), [ {
name: 'default',
description: 'Class declaration example.',
params: [],
return: [],
tags: [],
} ] );
const namedExport = fs.readFileSync(
Expand All @@ -109,11 +125,11 @@ test( 'IR - default (JSDoc in same file)', function( t ) {
);
t.deepEqual(
getIntermediateRepresentation( JSON.parse( namedExport )[ 0 ], JSON.parse( namedExportAST ) ),
[ { name: 'functionDeclaration', description: 'Function declaration example.', tags: [] } ]
[ { name: 'functionDeclaration', description: 'Function declaration example.', params: [], return: [], tags: [] } ]
);
t.deepEqual(
getIntermediateRepresentation( JSON.parse( namedExport )[ 1 ], JSON.parse( namedExportAST ) ),
[ { name: 'default', description: 'Function declaration example.', tags: [] } ]
[ { name: 'default', description: 'Function declaration example.', params: [], return: [], tags: [] } ]
);
t.end();
} );
Expand All @@ -136,6 +152,8 @@ test( 'IR - default (JSDoc in module dependency)', function( t ) {
[ {
name: 'default',
description: 'Function declaration.',
params: [],
return: [],
tags: [],
} ]
);
Expand All @@ -156,6 +174,8 @@ test( 'IR - default (JSDoc in module dependency)', function( t ) {
[ {
name: 'default',
description: 'Function declaration.',
params: [],
return: [],
tags: [],
} ]
);
Expand All @@ -170,6 +190,8 @@ test( 'IR - named (JSDoc in export statement)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenClass ) ), [ {
name: 'MyDeclaration',
description: 'My declaration example.',
params: [],
return: [],
tags: [],
} ] );
const tokenFn = fs.readFileSync(
Expand All @@ -179,6 +201,8 @@ test( 'IR - named (JSDoc in export statement)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenFn ) ), [ {
name: 'myDeclaration',
description: 'My declaration example.',
params: [],
return: [],
tags: [],
} ] );
const tokenVariable = fs.readFileSync(
Expand All @@ -188,15 +212,17 @@ test( 'IR - named (JSDoc in export statement)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenVariable ) ), [ {
name: 'myDeclaration',
description: 'My declaration example.',
params: [],
return: [],
tags: [],
} ] );
const tokenVariables = fs.readFileSync(
path.join( __dirname, './fixtures/named-variables.json' ),
'utf-8'
);
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenVariables ) ), [
{ name: 'firstDeclaration', description: 'My declaration example.', tags: [] },
{ name: 'secondDeclaration', description: 'My declaration example.', tags: [] },
{ name: 'firstDeclaration', description: 'My declaration example.', params: [], return: [], tags: [] },
{ name: 'secondDeclaration', description: 'My declaration example.', params: [], return: [], tags: [] },
] );
t.end();
} );
Expand All @@ -213,6 +239,8 @@ test( 'IR - named (JSDoc in same file)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( token ), JSON.parse( ast ) ), [ {
name: 'myDeclaration',
description: 'My declaration example.',
params: [],
return: [],
tags: [] },
] );
const tokenObject = fs.readFileSync(
Expand All @@ -226,6 +254,8 @@ test( 'IR - named (JSDoc in same file)', function( t ) {
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokenObject ), JSON.parse( astObject ) ), [ {
name: 'myDeclaration',
description: 'My declaration example.',
params: [],
return: [],
tags: [] },
] );
const tokens = fs.readFileSync(
Expand All @@ -237,9 +267,9 @@ test( 'IR - named (JSDoc in same file)', function( t ) {
'utf-8'
);
t.deepEqual( getIntermediateRepresentation( JSON.parse( tokens ), JSON.parse( asts ) ), [
{ name: 'functionDeclaration', description: 'Function declaration example.', tags: [] },
{ name: 'variableDeclaration', description: 'Variable declaration example.', tags: [] },
{ name: 'ClassDeclaration', description: 'Class declaration example.', tags: [] },
{ name: 'functionDeclaration', description: 'Function declaration example.', params: [], return: [], tags: [] },
{ name: 'variableDeclaration', description: 'Variable declaration example.', params: [], return: [], tags: [] },
{ name: 'ClassDeclaration', description: 'Class declaration example.', params: [], return: [], tags: [] },
] );
const foo = fs.readFileSync(
path.join( __dirname, './fixtures/named-identifiers-and-inline.json' ),
Expand All @@ -250,11 +280,11 @@ test( 'IR - named (JSDoc in same file)', function( t ) {
'utf-8'
);
t.deepEqual( getIntermediateRepresentation( JSON.parse( foo )[ 0 ], JSON.parse( bar ) ), [
{ name: 'functionDeclaration', description: 'Function declaration example.', tags: [] },
{ name: 'ClassDeclaration', description: 'Class declaration example.', tags: [] },
{ name: 'functionDeclaration', description: 'Function declaration example.', params: [], return: [], tags: [] },
{ name: 'ClassDeclaration', description: 'Class declaration example.', params: [], return: [], tags: [] },
] );
t.deepEqual( getIntermediateRepresentation( JSON.parse( foo )[ 1 ], JSON.parse( bar ) ), [
{ name: 'variableDeclaration', description: 'Variable declaration example.', tags: [] },
{ name: 'variableDeclaration', description: 'Variable declaration example.', params: [], return: [], tags: [] },
] );
t.end();
} );
Expand All @@ -270,7 +300,7 @@ test( 'IR - named (JSDoc in module dependency)', function( t ) {
) );
t.deepEqual(
getIntermediateRepresentation( JSON.parse( tokenDefault ), { body: [] }, getModule ),
[ { name: 'default', description: 'Module declaration.', tags: [] } ]
[ { name: 'default', description: 'Module declaration.', params: [], return: [], tags: [] } ]
);
const tokenImportNamed = fs.readFileSync(
path.join( __dirname, './fixtures/named-import-named.json' ),
Expand All @@ -282,15 +312,15 @@ test( 'IR - named (JSDoc in module dependency)', function( t ) {
) );
t.deepEqual(
getIntermediateRepresentation( JSON.parse( tokenImportNamed ), { body: [] }, getModuleImportNamed ),
[ { name: 'myDeclaration', description: 'My declaration example.', tags: [] } ]
[ { name: 'myDeclaration', description: 'My declaration example.', params: [], return: [], tags: [] } ]
);
const tokenDefaultExported = fs.readFileSync(
path.join( __dirname, './fixtures/named-default-exported.json' ),
'utf-8'
);
t.deepEqual(
getIntermediateRepresentation( JSON.parse( tokenDefaultExported ), { body: [] }, getModule ),
[ { name: 'moduleName', description: 'Module declaration.', tags: [] } ]
[ { name: 'moduleName', description: 'Module declaration.', params: [], return: [], tags: [] } ]
);
const tokenImportNamespace = fs.readFileSync(
path.join( __dirname, './fixtures/named-import-namespace.json' ),
Expand All @@ -314,7 +344,7 @@ test( 'IR - named (JSDoc in module dependency)', function( t ) {
};
t.deepEqual(
getIntermediateRepresentation( JSON.parse( tokenImportNamespace ), JSON.parse( astImportNamespace ), getModuleImportNamespace ),
[ { name: 'variables', description: 'Undocumented declaration.', tags: [] } ]
[ { name: 'variables', description: 'Undocumented declaration.', params: [], return: [], tags: [] } ]
);
t.end();
} );
Expand All @@ -331,9 +361,9 @@ test( 'IR - namespace (JSDoc in module dependency)', function( t ) {
t.deepEqual(
getIntermediateRepresentation( JSON.parse( token ), { body: [] }, getModule ),
[
{ name: 'myVariable', description: 'Named variable.', tags: [] },
{ name: 'myFunction', description: 'Named function.', tags: [] },
{ name: 'MyClass', description: 'Named class.', tags: [] },
{ name: 'myVariable', description: 'Named variable.', params: [], return: [], tags: [] },
{ name: 'myFunction', description: 'Named function.', params: [], return: [], tags: [] },
{ name: 'MyClass', description: 'Named class.', params: [], return: [], tags: [] },
]
);
const tokenCommented = fs.readFileSync(
Expand All @@ -343,9 +373,9 @@ test( 'IR - namespace (JSDoc in module dependency)', function( t ) {
t.deepEqual(
getIntermediateRepresentation( JSON.parse( tokenCommented ), { body: [] }, getModule ),
[
{ name: 'myVariable', description: 'Named variable.', tags: [] },
{ name: 'myFunction', description: 'Named function.', tags: [] },
{ name: 'MyClass', description: 'Named class.', tags: [] },
{ name: 'myVariable', description: 'Named variable.', params: [], return: [], tags: [] },
{ name: 'myFunction', description: 'Named function.', params: [], return: [], tags: [] },
{ name: 'MyClass', description: 'Named class.', params: [], return: [], tags: [] },
]
);
t.end();
Expand Down

0 comments on commit 7d5fe5c

Please sign in to comment.