-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports NPM 8 and convert tests from Mocha to Jest (#1084)
- Loading branch information
Showing
48 changed files
with
41,088 additions
and
13,087 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ coverage | |
.idea | ||
/.nyc_output | ||
.history | ||
.vscode | ||
.DS_Store |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ coverage | |
examples | ||
tests | ||
*.test.js | ||
__mocks__ | ||
.nyc_output | ||
.github | ||
yarn.lock | ||
|
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,13 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Mock object for fs | ||
*/ | ||
|
||
module.exports = { | ||
copy: jest.fn().mockResolvedValue(), | ||
pathExists: jest.fn().mockResolvedValue(true), | ||
pathExistsSync: jest.fn().mockReturnValue(false), | ||
removeSync: jest.fn().mockReturnValue(), | ||
remove: jest.fn() | ||
}; |
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,27 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Mock object for fs | ||
*/ | ||
|
||
const streamMock = { | ||
on: jest.fn() | ||
}; | ||
|
||
const statMock = { | ||
isDirectory: jest.fn() | ||
}; | ||
|
||
const actual = jest.requireActual('fs'); | ||
|
||
module.exports = { | ||
...actual, | ||
createWriteStream: jest.fn().mockReturnValue(streamMock), | ||
readFileSync: jest.fn(), | ||
statSync: jest.fn().mockReturnValue(statMock), | ||
writeFileSync: jest.fn(), | ||
copyFileSync: jest.fn(), | ||
|
||
_streamMock: streamMock, | ||
_statMock: statMock | ||
}; |
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 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Mock object for glob | ||
*/ | ||
|
||
module.exports = { | ||
sync: jest.fn() | ||
}; |
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,32 @@ | ||
'use strict'; | ||
|
||
const statsMock = { | ||
compilation: { | ||
errors: [], | ||
compiler: { | ||
outputPath: 'statsMock-outputPath' | ||
}, | ||
modules: [] | ||
}, | ||
toString: jest.fn().mockReturnValue('testStats'), | ||
hasErrors() { | ||
return Boolean(this.compilation.errors.length); | ||
} | ||
}; | ||
|
||
const compilerMock = { | ||
run: jest.fn().mockImplementation(cb => cb(null, statsMock)), | ||
watch: jest.fn().mockImplementation(cb => cb(null, statsMock)), | ||
hooks: { | ||
beforeCompile: { | ||
tapPromise: jest.fn() | ||
} | ||
}, | ||
plugin: jest.fn().mockImplementation((name, cb) => cb(null, {})) | ||
}; | ||
|
||
const mock = jest.fn().mockReturnValue(compilerMock); | ||
mock.compilerMock = compilerMock; | ||
mock.statsMock = statsMock; | ||
|
||
module.exports = mock; |
23 changes: 23 additions & 0 deletions
23
examples/include-external-npm-packages-lock-file/_setup.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,23 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
module.exports = async (originalFixturePath, fixturePath, utils) => { | ||
const pluginPath = path.resolve(originalFixturePath, '..', '..'); | ||
|
||
const SLS_CONFIG_PATH = path.join(fixturePath, 'serverless.yml'); | ||
const WEBPACK_CONFIG_PATH = path.join(fixturePath, 'webpack.config.js'); | ||
const PACKAGE_JSON_PATH = path.join(fixturePath, 'package.json'); | ||
const LOCK_PATH = path.join(fixturePath, 'package-lock.json'); | ||
|
||
await Promise.all([ | ||
utils.replaceInFile(SLS_CONFIG_PATH, '- serverless-webpack', `- ${pluginPath}`), | ||
utils.replaceInFile(WEBPACK_CONFIG_PATH, "'serverless-webpack'", `'${pluginPath}'`), | ||
utils.replaceInFile(PACKAGE_JSON_PATH, 'file:../..', `file:${pluginPath}`), | ||
utils.replaceInFile(LOCK_PATH, '../..', `${pluginPath}`) | ||
]); | ||
|
||
const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'; | ||
|
||
return utils.spawnProcess(command, ['install'], { cwd: __dirname }); | ||
}; |
17 changes: 17 additions & 0 deletions
17
examples/include-external-npm-packages-lock-file/handler.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,17 @@ | ||
// Should keep side-effects scripts | ||
import 'dotenv/config'; | ||
// Should be included as fbgraph is not marked as sideEffect free | ||
import { fbgraph } from 'fbgraph'; | ||
// Should keep named imports | ||
import { toUpper } from 'lodash'; | ||
// Should keep default imports | ||
import isEqual from 'lodash.isequal'; | ||
|
||
function getMessage() { | ||
return isEqual(true, false) ? 'noop' : toUpper('hello fb & aws'); | ||
} | ||
|
||
export const hello = function (event, context, cb) { | ||
const message = getMessage(); | ||
cb(null, { message, event }); | ||
}; |
Oops, something went wrong.