-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update readme, plus more coverage
- Loading branch information
Showing
6 changed files
with
115 additions
and
31 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 @@ | ||
/* eslint-env node, jest */ | ||
const Babel = require('babel-standalone'); | ||
|
||
const code = `let i = 0; while (true) { i++; }; done(i)`; | ||
|
||
let done = jest.fn(); | ||
|
||
beforeEach(() => { | ||
done = jest.fn(); | ||
}); | ||
|
||
const transform = id => code => Babel.transform(new Function(code).toString(), { | ||
plugins: [id], | ||
}).code; // eslint-disable-line no-new-func | ||
|
||
const run = code => { | ||
// console.log(code); | ||
eval(`(${code})()`); // eslint-disable-line no-eval | ||
}; | ||
|
||
test('no callback', () => { | ||
const id = 'lp1'; | ||
Babel.registerPlugin(id, require('../lib')(100)); | ||
const after = transform(id)(code); | ||
run(after); | ||
expect(done).toBeCalledWith(expect.any(Number)); | ||
}); | ||
|
||
test('anonymous callback', () => { | ||
const id = 'lp2'; | ||
Babel.registerPlugin(id, require('../lib')(100, line => done(`line: ${line}`))); | ||
const after = transform(id)(code); | ||
run(after); | ||
expect(done).toHaveBeenCalledWith('line: 2'); | ||
}); | ||
|
||
test('arrow function callback', () => { | ||
const id = 'lp3'; | ||
const callback = line => done(`lp3: ${line}`); | ||
|
||
Babel.registerPlugin(id, require('../lib')(100, callback)); | ||
const after = transform(id)(code); | ||
run(after); | ||
expect(done).toHaveBeenCalledWith(`${id}: 2`); | ||
}); | ||
|
||
test('named function callback', () => { | ||
const id = 'lp4'; | ||
function callback(line, ch) { | ||
done(`lp4: ${line}`); | ||
} | ||
|
||
Babel.registerPlugin(id, require('../lib')(100, callback)); | ||
const after = transform(id)(code); | ||
run(after); | ||
expect(done).toHaveBeenCalledWith(`${id}: 2`); | ||
}); |
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