-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from iambumblehead/add-mocha-tests-re-#186
added mocha tests
- Loading branch information
Showing
12 changed files
with
103 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
`esmock` relies on unit-tests to verify its behaviour. To get started, clone esmock and add a test to [one of the test runner folders here.][0] From esmock's root folder use `npm install && npm run test:install` to fetch all dependencies then, from whichever test folder is being used, `npm test` will run tests. | ||
|
||
If `esmock` is failing for you, feel free to submit a PR that reproduces the issue with a failing unit-test. If available, I will try to resolve the issue and publish a new version of `esmock` with the solution. | ||
|
||
Please do not submit PRs to convert esmock to typescript or add build scripts. Typescript and build scripts are fine, however, esmock's current setup is ideal for me now. | ||
|
||
|
||
[0]: https://github.com/iambumblehead/esmock/tree/master/tests |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"type": "module", | ||
"description": "esmock unit tests, mocha", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/iambumblehead/esmock.git" | ||
}, | ||
"dependencies": { | ||
"mocha": "^10.1.0", | ||
"chai": "^4.3.7", | ||
"chai-http": "^4.3.0", | ||
"esmock": "file:..", | ||
"express": "^4.18.2", | ||
"passport": "^0.6.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha --loader=esmock" | ||
} | ||
} |
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,24 @@ | ||
import express from 'express' | ||
import passport from 'passport' | ||
|
||
const app = express() | ||
const port = 7575 | ||
|
||
passport.use('bearerStrategy') | ||
|
||
// app.use(passport.initialize()) | ||
if (typeof passport.initialize !== 'function') { | ||
throw new Error('inavalid mock') | ||
} | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Hello World!') | ||
}) | ||
|
||
const server = app.listen(port, () => { | ||
console.log(`Example app listening on port ${port}`) | ||
}) | ||
|
||
export default Object.assign(app, { | ||
close: () => server.close() | ||
}) |
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,29 @@ | ||
import chai from 'chai' | ||
import chaiHttp from 'chai-http' | ||
import esmock from 'esmock' | ||
|
||
chai.use(chaiHttp) | ||
chai.should() | ||
|
||
const app = await esmock('../src/app.js', { | ||
passport: { | ||
use: bearerStrategy => `mocked${bearerStrategy}` | ||
} | ||
}, {}) | ||
|
||
describe('/', () => { | ||
it('should work', done => { | ||
try { | ||
chai | ||
.request(app.default) | ||
.get('/') | ||
.end((err, res) => { | ||
app.close() | ||
res.should.have.status(200) | ||
}) | ||
done() | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
}) | ||
}) |