forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
124,992 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
|
||
require('../typescript'); | ||
|
||
test('dummy test', () => { | ||
expect(1).toBe(1); | ||
}); |
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,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
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,31 @@ | ||
const vm = require('vm'); | ||
const CoverageInstrumenter = require('@jest/coverage').default; | ||
|
||
const script = new vm.Script( | ||
` | ||
function thing() { | ||
if (Math.random() > 0.5) { | ||
output = 'success!'; | ||
} else { | ||
output = 'failure'; | ||
} | ||
} | ||
thing(); | ||
` | ||
); | ||
|
||
async function doThings() { | ||
const context = vm.createContext({output: ''}); | ||
const instrumenter = new CoverageInstrumenter(); | ||
|
||
await instrumenter.startInstrumenting(); | ||
|
||
script.runInContext(context); | ||
|
||
const coverage = await instrumenter.stopInstrumenting(); | ||
|
||
return JSON.stringify(coverage); | ||
} | ||
|
||
doThings().then(console.log, console.error); |
Oops, something went wrong.