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.
fix: load transformers before installing require hooks (jestjs#7752)
- Loading branch information
1 parent
c37a185
commit bfaa70b
Showing
10 changed files
with
119 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
const greeting = require('../'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-setup-custom-transform'); | ||
|
||
test('should exist setup file', () => { | ||
const files = fs.readdirSync(DIR); | ||
expect(files).toHaveLength(1); | ||
const setup = fs.readFileSync(path.join(DIR, files[0]), 'utf8'); | ||
expect(setup).toBe('setup'); | ||
}); | ||
|
||
test('should transform imported file', () => { | ||
expect(greeting).toEqual('hello, world!'); | ||
}); |
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,3 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
|
||
module.exports = 'hello!'; |
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,9 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node", | ||
"globalSetup": "<rootDir>/setup.js", | ||
"transform": { | ||
"^.+\\.js$": "<rootDir>/transformer.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) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const {createDirectory} = require('jest-util'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-setup-custom-transform'); | ||
|
||
module.exports = function() { | ||
return new Promise(resolve => { | ||
createDirectory(DIR); | ||
const fileId = crypto.randomBytes(20).toString('hex'); | ||
fs.writeFileSync(path.join(DIR, fileId), 'setup'); | ||
resolve(); | ||
}); | ||
}; |
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,15 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
|
||
'use strict'; | ||
|
||
const fileToTransform = require.resolve('./index.js'); | ||
|
||
module.exports = { | ||
process(src, filename) { | ||
if (filename === fileToTransform) { | ||
return src.replace('hello', 'hello, world'); | ||
} | ||
|
||
return src; | ||
}, | ||
}; |
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