Skip to content

Commit 7ce0a42

Browse files
authored
Add coverage (#7)
* Push to codecov from Travis * Add more examples to readme * Fix lint errors * Add badge * Update Jest
1 parent 58bf03f commit 7ce0a42

File tree

6 files changed

+269
-2397
lines changed

6 files changed

+269
-2397
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ module.exports = {
1313
'import/no-unresolved': 0, // TypeScript can handle it
1414
'import/no-extraneous-dependencies': 0,
1515
'object-curly-newline': 0, // let Prettier handle it
16+
'operator-linebreak': 0, // let Prettier handle it
1617
'no-underscore-dangle': 0,
18+
'no-unused-vars': 0, // TypeScript can handle it
1719
'react/jsx-filename-extension': 0,
1820
'react/destructuring-assignment': 0,
1921
'space-before-function-paren': 0, // let Prettier handle it

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.cache
22
.DS_Store
3+
coverage
34
pkg
45
node_modules
56
yarn.lock

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ jobs:
88
script: npm run lint:js
99
- stage: test
1010
name: 'Run tests'
11-
script: npm run test
11+
script: npm run test:coverage
12+
after_success:
13+
- npx codecov

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
[![version (scoped)](https://img.shields.io/npm/v/@manifoldco/swagger-to-ts.svg)](https://www.npmjs.com/package/@manifoldco/swagger-to-ts)
1+
[![version
2+
(scoped)](https://img.shields.io/npm/v/@manifoldco/swagger-to-ts.svg)](https://www.npmjs.com/package/@manifoldco/swagger-to-ts)
3+
[![codecov](https://codecov.io/gh/manifoldco/swagger-to-ts/branch/master/graph/badge.svg)](https://codecov.io/gh/manifoldco/swagger-to-ts)
24

35
# 📘️ swagger-to-ts
46

@@ -19,7 +21,7 @@ To compare actual generated output, see the [example](./example) folder.
1921

2022
## Usage
2123

22-
### CLI
24+
#### Basic example (CLI)
2325

2426
```bash
2527
npx @manifoldco/swagger-to-ts schema.yaml --namespace OpenAPI --output schema.ts
@@ -32,6 +34,36 @@ This will save a `schema.ts` file in the current folder under the TypeScript
3234
collision among specs is highly likely). The CLI can accept YAML or JSON for
3335
the input file.
3436

37+
#### CamelCasing properties
38+
39+
You can also convert `snake_case` keys to `camelCase` by adding the
40+
`--camelcase` flag:
41+
42+
```bash
43+
npx @manifoldco/swagger-to-ts schema.yaml --camelcase --namespace OpenAPI --output schema.ts
44+
45+
# 🚀 schema.yaml -> schema.ts [2ms]
46+
```
47+
48+
#### Generating multiple schemas
49+
50+
Say you have multiple schemas you need to parse. I’ve found the simplest way
51+
to do that is just to use npm scripts. In your `package.json`, you can do
52+
something like the following:
53+
54+
```json
55+
"scripts": {
56+
"generate:specs": "npm run generate:specs:one && npm run generate:specs:two",
57+
"generate:specs:one": "npx @manifoldco/swagger-to-ts one.yaml -o one.ts",
58+
"generate:specs:two": "npx @manifoldco/swagger-to-ts two.yaml -o two.ts"
59+
}
60+
```
61+
62+
Rinse and repeat for more specs.
63+
64+
For anything more complicated or for generating specs more dynamically, you
65+
can also use the Node API (below).
66+
3567
### Node
3668

3769
```bash

jest.config.js

Lines changed: 1 addition & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -1,176 +1,4 @@
1-
// For a detailed explanation regarding each configuration property, visit:
2-
// https://jestjs.io/docs/en/configuration.html
3-
41
module.exports = {
5-
// All imported modules in your tests should be mocked automatically
6-
// automock: false,
7-
8-
// Stop running tests after the first failure
9-
// bail: false,
10-
11-
// Respect "browser" field in package.json when resolving modules
12-
// browser: false,
13-
14-
// The directory where Jest should store its cached dependency information
15-
// cacheDirectory: "/var/folders/cb/jmpdtwj56mj1fyyct_6rxqb00000gn/T/jest_dx",
16-
17-
// Automatically clear mock calls and instances between every test
18-
// clearMocks: false,
19-
20-
// Indicates whether the coverage information should be collected while executing the test
21-
// collectCoverage: false,
22-
23-
// An array of glob patterns indicating a set of files for which coverage information should be collected
24-
// collectCoverageFrom: null,
25-
26-
// The directory where Jest should output its coverage files
27-
// coverageDirectory: null,
28-
29-
// An array of regexp pattern strings used to skip coverage collection
30-
// coveragePathIgnorePatterns: [
31-
// "/node_modules/"
32-
// ],
33-
34-
// A list of reporter names that Jest uses when writing coverage reports
35-
// coverageReporters: [
36-
// "json",
37-
// "text",
38-
// "lcov",
39-
// "clover"
40-
// ],
41-
42-
// An object that configures minimum threshold enforcement for coverage results
43-
// coverageThreshold: null,
44-
45-
// Make calling deprecated APIs throw helpful error messages
46-
// errorOnDeprecated: false,
47-
48-
// Force coverage collection from ignored files usin a array of glob patterns
49-
// forceCoverageMatch: [],
50-
51-
// A path to a module which exports an async function that is triggered once before all test suites
52-
// globalSetup: null,
53-
54-
// A path to a module which exports an async function that is triggered once after all test suites
55-
// globalTeardown: null,
56-
57-
// A set of global variables that need to be available in all test environments
58-
globals: {
59-
'ts-jest': {
60-
tsConfig: 'tsconfig.json',
61-
},
62-
},
63-
64-
// An array of directory names to be searched recursively up from the requiring module's location
65-
moduleDirectories: ['node_modules', 'src'],
66-
67-
// An array of file extensions your modules use
68-
moduleFileExtensions: ['ts', 'tsx', 'js'],
69-
70-
// A map from regular expressions to module names that allow to stub out resources with a single module
71-
// moduleNameMapper: {},
72-
73-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
74-
// modulePathIgnorePatterns: [],
75-
76-
// Activates notifications for test results
77-
// notify: false,
78-
79-
// An enum that specifies notification mode. Requires { notify: true }
80-
// notifyMode: "always",
81-
82-
// A preset that is used as a base for Jest's configuration
83-
// preset: null,
84-
85-
// Run tests from one or more projects
86-
// projects: null,
87-
88-
// Use this configuration option to add custom reporters to Jest
89-
// reporters: undefined,
90-
91-
// Automatically reset mock state between every test
92-
// resetMocks: false,
93-
94-
// Reset the module registry before running each individual test
95-
// resetModules: false,
96-
97-
// A path to a custom resolver
98-
// resolver: null,
99-
100-
// Automatically restore mock state between every test
101-
// restoreMocks: false,
102-
103-
// The root directory that Jest should scan for tests and modules within
104-
// rootDir: null,
105-
106-
// A list of paths to directories that Jest should use to search for files in
107-
// roots: [
108-
// "<rootDir>"
109-
// ],
110-
111-
// Allows you to use a custom runner instead of Jest's default test runner
112-
// runner: "jest-runner",
113-
114-
// The paths to modules that run some code to configure or set up the testing environment before each test
115-
// setupFiles: [],
116-
117-
// The path to a module that runs some code to configure or set up the testing framework before each test
118-
// setupTestFrameworkScriptFile: null,
119-
120-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
121-
// snapshotSerializers: [],
122-
123-
// The test environment that will be used for testing
2+
preset: 'ts-jest',
1243
testEnvironment: 'node',
125-
126-
// Options that will be passed to the testEnvironment
127-
// testEnvironmentOptions: {},
128-
129-
// Adds a location field to test results
130-
// testLocationInResults: false,
131-
132-
// The glob patterns Jest uses to detect test files
133-
testMatch: ['**/tests/*.test.ts'],
134-
135-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
136-
// testPathIgnorePatterns: [
137-
// "/node_modules/"
138-
// ],
139-
140-
// The regexp pattern Jest uses to detect test files
141-
// testRegex: "",
142-
143-
// This option allows the use of a custom results processor
144-
// testResultsProcessor: null,
145-
146-
// This option allows use of a custom test runner
147-
// testRunner: "jasmine2",
148-
149-
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
150-
// testURL: "http://localhost",
151-
152-
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
153-
// timers: "real",
154-
155-
// A map from regular expressions to paths to transformers
156-
transform: {
157-
'^.+\\.(ts|tsx)$': 'ts-jest',
158-
},
159-
160-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
161-
// transformIgnorePatterns: [
162-
// "/node_modules/"
163-
// ],
164-
165-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
166-
// unmockedModulePathPatterns: undefined,
167-
168-
// Indicates whether each individual test should be reported during the run
169-
// verbose: null,
170-
171-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
172-
// watchPathIgnorePatterns: [],
173-
174-
// Whether to use watchman for file crawling
175-
// watchman: true,
1764
};

0 commit comments

Comments
 (0)