-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update the test cases to use a single test file
- Loading branch information
Showing
11 changed files
with
182 additions
and
114 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...ut__/schema-data/public-methods/bundle.js → ...ut__/schema-data/public-methods.bundle.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../schema-data/public-methods/bundle.js.map → .../schema-data/public-methods.bundle.js.map
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
packages/build/__tests__/__snapshots__/schemaExtractor.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`schemaExtractorPlugin should extract a basic contract with public and private methods 1`] = ` | ||
{ | ||
"methods": [], | ||
"state": { | ||
"properties": { | ||
"count": { | ||
"type": "number", | ||
}, | ||
"startCoin": { | ||
"properties": { | ||
"amount": { | ||
"type": "string", | ||
}, | ||
"denom": { | ||
"type": "string", | ||
}, | ||
}, | ||
"type": "object", | ||
}, | ||
"tokens": { | ||
"items": { | ||
"properties": { | ||
"amount": { | ||
"type": "string", | ||
}, | ||
"denom": { | ||
"type": "string", | ||
}, | ||
}, | ||
"type": "object", | ||
}, | ||
"type": "array", | ||
}, | ||
}, | ||
"type": "object", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`schemaExtractorPlugin should extract methods from classes public methods 1`] = ` | ||
{ | ||
"methods": [ | ||
{ | ||
"functionName": "increment", | ||
"parameters": [], | ||
"returnType": { | ||
"type": "any", | ||
}, | ||
}, | ||
{ | ||
"functionName": "addToken", | ||
"parameters": [ | ||
{ | ||
"name": "denom", | ||
"type": { | ||
"type": "string", | ||
}, | ||
}, | ||
{ | ||
"name": "amount", | ||
"type": { | ||
"type": "string", | ||
}, | ||
}, | ||
], | ||
"returnType": { | ||
"type": "any", | ||
}, | ||
}, | ||
{ | ||
"functionName": "removeToken", | ||
"parameters": [ | ||
{ | ||
"name": "index", | ||
"type": { | ||
"type": "number", | ||
}, | ||
}, | ||
], | ||
"returnType": { | ||
"type": "any", | ||
}, | ||
}, | ||
], | ||
"state": { | ||
"properties": { | ||
"count": { | ||
"type": "number", | ||
}, | ||
"startCoin": { | ||
"properties": { | ||
"amount": { | ||
"type": "string", | ||
}, | ||
"denom": { | ||
"type": "string", | ||
}, | ||
}, | ||
"type": "object", | ||
}, | ||
"tokens": { | ||
"items": { | ||
"properties": { | ||
"amount": { | ||
"type": "string", | ||
}, | ||
"denom": { | ||
"type": "string", | ||
}, | ||
}, | ||
"type": "object", | ||
}, | ||
"type": "array", | ||
}, | ||
}, | ||
"type": "object", | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import fs from 'fs/promises'; | ||
import { join, resolve } from 'path'; | ||
import { HyperwebBuild, HyperwebBuildOptions, schemaExtractorPlugin } from '../src'; | ||
|
||
const outputDir = resolve(join(__dirname, '/../../../__output__/schema-data')); | ||
|
||
const runTest = async (fixtureName: string) => { | ||
const fixtureDir = resolve(join(__dirname, `/../../../__fixtures__/schema-data/${fixtureName}`)); | ||
const schemaOutputPath = join(outputDir, `${fixtureName}.schema.json`); | ||
|
||
const buildOptions: Partial<HyperwebBuildOptions> = { | ||
entryPoints: [join(fixtureDir, 'index.ts')], | ||
outfile: join(outputDir, `${fixtureName}.bundle.js`), | ||
customPlugins: [ | ||
schemaExtractorPlugin({ | ||
outputPath: schemaOutputPath, | ||
baseDir: fixtureDir, | ||
include: [/\.ts$/], | ||
exclude: [/node_modules/, /\.test\.ts$/], | ||
}), | ||
], | ||
}; | ||
|
||
await HyperwebBuild.build(buildOptions); | ||
const schemaContent = await fs.readFile(schemaOutputPath, 'utf-8'); | ||
return JSON.parse(schemaContent); | ||
}; | ||
|
||
describe('schemaExtractorPlugin', () => { | ||
it('should extract a basic contract with public and private methods', async () => { | ||
const schemaData = await runTest('state-export'); | ||
|
||
expect(schemaData).toHaveProperty('state'); | ||
expect(schemaData.state).toHaveProperty('type', 'object'); | ||
expect(schemaData.state).toHaveProperty('properties'); | ||
|
||
expect(schemaData).toHaveProperty('methods'); | ||
expect(schemaData.methods).toEqual([]); | ||
|
||
expect(schemaData).toMatchSnapshot(); | ||
}); | ||
|
||
it('should extract methods from classes public methods', async () => { | ||
const schemaData = await runTest('public-methods'); | ||
|
||
expect(schemaData).toHaveProperty('state'); | ||
expect(schemaData.state).toHaveProperty('type', 'object'); | ||
expect(schemaData.state).toHaveProperty('properties'); | ||
|
||
const methodNames = schemaData.methods.map((method: any) => method.functionName); | ||
expect(methodNames).toContain('addToken'); | ||
expect(methodNames).toContain('increment'); | ||
expect(methodNames).toContain('removeToken'); | ||
expect(methodNames).not.toContain('reset'); | ||
|
||
expect(schemaData).toMatchSnapshot(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.