forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instrumenting preprocessors (jestjs#1336)
* Instrumenting preprocessors * Address Comments
- Loading branch information
1 parent
a77f88c
commit 6760c6c
Showing
10 changed files
with
185 additions
and
30 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
20 changes: 20 additions & 0 deletions
20
...n_tests/transform/custom-instrumenting-preprocessor/__tests__/custom-preprocessor-test.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,20 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
|
||
require('../src'); | ||
|
||
it('instruments by setting global.__INSTRUMENTED__', () => { | ||
expect(global.__INSTRUMENTED__).toBe(true); | ||
}); | ||
|
||
it('preprocesses by setting global.__PREPROCESSED__', () => { | ||
expect(global.__PREPROCESSED__).toBe(true); | ||
}); |
5 changes: 5 additions & 0 deletions
5
integration_tests/transform/custom-instrumenting-preprocessor/package.json
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": { | ||
"scriptPreprocessor": "<rootDir>/preprocessor.js" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
integration_tests/transform/custom-instrumenting-preprocessor/preprocessor.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,22 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
INSTRUMENTS: true, | ||
process(src, filename, config, options) { | ||
src = `${src};\nglobal.__PREPROCESSED__ = true;`; | ||
|
||
if (options.instrument) { | ||
src = `${src};\nglobal.__INSTRUMENTED__ = true;`; | ||
} | ||
|
||
return src; | ||
}, | ||
}; |
11 changes: 11 additions & 0 deletions
11
integration_tests/transform/custom-instrumenting-preprocessor/src/index.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,11 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = {a: 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
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,34 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
import type {Config, Path} from 'types/Config'; | ||
|
||
export type PreprocessorOptions = { | ||
instrument: boolean, | ||
}; | ||
|
||
export type Preprocessor = { | ||
INSTRUMENTS?: boolean, | ||
|
||
getCacheKey: ( | ||
fileData: string, | ||
filePath: Path, | ||
configStr: string, | ||
options: PreprocessorOptions, | ||
) => string, | ||
|
||
process: ( | ||
sourceText: string, | ||
sourcePath: Path, | ||
config: Config, | ||
options?: PreprocessorOptions, | ||
) => string, | ||
}; |