Skip to content

Commit

Permalink
feat: rewrite to TS and start using Jest (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu authored Mar 21, 2022
1 parent 58b44a9 commit 1d43660
Show file tree
Hide file tree
Showing 15 changed files with 7,573 additions and 2,356 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.vscode
node_modules
node_modules
lib
dist
coverage
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,36 @@ Save the result in a file by `-o, --output` flag:
asyncapi-converter streetlights.yml -o streetlights2.yml
```

### As a package
### In JS

```js
const fs = require('fs');
const { convert } = require('@asyncapi/converter')

try {
const asyncapi = fs.readFileSync('streetlights.yml', 'utf-8')
console.log(convert(asyncapi, '2.0.0', {
id: 'urn:com.asyncapi.streetlights'
}))
id: 'urn:com.asyncapi.streetlights'
}));
} catch (e) {
console.error(e);
}
```

### In TS

```ts
import { convert } from '@asyncapi/converter';
import type { ConvertVersion, ConvertOptions } from '@asyncapi/converter';

try {
const toVersion: ConvertVersion = '2.0.0';
const options: ConvertOptions = {
id: 'urn:com.asyncapi.streetlights'
};

const asyncapi = fs.readFileSync('streetlights.yml', 'utf-8')
console.log(convert(asyncapi, toVersion, options));
} catch (e) {
console.error(e)
}
Expand Down
26 changes: 26 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
coverageReporters: [
'json-summary',
'lcov',
'text'
],
preset: 'ts-jest',
// The root of your source code, typically /src
// `<rootDir>` is a token Jest substitutes
roots: ['<rootDir>'],

// Test spec file resolution pattern
// Matches parent folder `__tests__` and filename
// should contain `test` or `spec`.
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
// Module file extensions for importing
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testTimeout: 10000,
collectCoverageFrom: [
'src/**'
],
};

export default config;
109 changes: 0 additions & 109 deletions lib/helpers.js

This file was deleted.

Loading

0 comments on commit 1d43660

Please sign in to comment.