-
-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: @feathers/cli: introduce option to choose jest for tests instea…
…d of mocha (#1057)
- Loading branch information
Showing
18 changed files
with
345 additions
and
110 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/generator-feathers/generators/app/configs/eslintrc.json.js
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,33 @@ | ||
module.exports = generator => { | ||
const { props } = generator; | ||
const config = { | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2017 | ||
}, | ||
"extends": "eslint:recommended", | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
2 | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
}; | ||
config.env[props.tester] = true; | ||
return config; | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
configDefault: require('./config.default.json.js'), | ||
configProduction: require('./config.production.json.js'), | ||
package: require('./package.json.js') | ||
package: require('./package.json.js'), | ||
eslintrc: require('./eslintrc.json.js') | ||
}; |
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
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
57 changes: 57 additions & 0 deletions
57
packages/generator-feathers/generators/app/templates/app.test.jest.js
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,57 @@ | ||
const rp = require('request-promise'); | ||
const url = require('url'); | ||
const app = require('../<%= src %>/app'); | ||
|
||
const port = app.get('port') || 3030; | ||
const getUrl = pathname => url.format({ | ||
hostname: app.get('host') || 'localhost', | ||
protocol: 'http', | ||
port, | ||
pathname | ||
}); | ||
|
||
describe('Feathers application tests (with jest)', () => { | ||
beforeAll(done => { | ||
this.server = app.listen(port); | ||
this.server.once('listening', () => done()); | ||
}); | ||
|
||
afterAll(done => { | ||
this.server.close(done); | ||
}); | ||
|
||
it('starts and shows the index page', () => { | ||
expect.assertions(1); | ||
return rp(getUrl()).then( | ||
body => expect(body.indexOf('<html>')).not.toBe(-1) | ||
); | ||
}); | ||
|
||
describe('404', () => { | ||
it('shows a 404 HTML page', () => { | ||
expect.assertions(2); | ||
return rp({ | ||
url: getUrl('path/to/nowhere'), | ||
headers: { | ||
'Accept': 'text/html' | ||
} | ||
}).catch(res => { | ||
expect(res.statusCode).toBe(404); | ||
expect(res.error.indexOf('<html>')).not.toBe(-1); | ||
}); | ||
}); | ||
|
||
it('shows a 404 JSON error without stack trace', () => { | ||
expect.assertions(4); | ||
return rp({ | ||
url: getUrl('path/to/nowhere'), | ||
json: true | ||
}).catch(res => { | ||
expect(res.statusCode).toBe(404); | ||
expect(res.error.code).toBe(404); | ||
expect(res.error.message).toBe('Page not found'); | ||
expect(res.error.name).toBe('NotFound'); | ||
}); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
29 changes: 0 additions & 29 deletions
29
packages/generator-feathers/generators/app/templates/static/.eslintrc.json
This file was deleted.
Oops, something went wrong.
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
26 changes: 26 additions & 0 deletions
26
packages/generator-feathers/generators/hook/templates/test-async.jest.js
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,26 @@ | ||
const feathers = require('@feathersjs/feathers'); | ||
const <%= camelName %> = require('../../<%= libDirectory %>/hooks/<%= kebabName %>'); | ||
|
||
describe('\'<%= name %>\' hook', () => { | ||
let app; | ||
|
||
beforeEach(() => { | ||
app = feathers(); | ||
|
||
app.use('/dummy', { | ||
async get(id) { | ||
return { id }; | ||
} | ||
}); | ||
|
||
app.service('dummy').hooks({ | ||
<% if(type){ %><%= type %>: <%= camelName %>()<% } %> | ||
}); | ||
}); | ||
|
||
it('runs the hook', async () => { | ||
expect.assertions(1); | ||
const result = await app.service('dummy').get('test'); | ||
expect(result).toEqual({ id: 'test' }); | ||
}); | ||
}); |
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
packages/generator-feathers/generators/hook/templates/test.jest.js
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,26 @@ | ||
const feathers = require('@feathersjs/feathers'); | ||
const <%= camelName %> = require('../../<%= libDirectory %>/hooks/<%= kebabName %>'); | ||
|
||
describe('\'<%= name %>\' hook', () => { | ||
let app; | ||
|
||
beforeEach(() => { | ||
app = feathers(); | ||
|
||
app.use('/dummy', { | ||
get(id) { | ||
return Promise.resolve({ id }); | ||
} | ||
}); | ||
|
||
app.service('dummy').hooks({ | ||
<% if(type){ %><%= type %>: <%= camelName %>()<% } %> | ||
}); | ||
}); | ||
|
||
it('runs the hook', () => { | ||
return app.service('dummy').get('test').then(result => { | ||
expect(result).toEqual({ id: 'test' }); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
Oops, something went wrong.