-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for createFilter
- increases coverage of get-options-overrides significantly - couldn't figure out `rootDirs` -- either the code or my tests are wrong, so just skip that one for now - refactor: move makeStubbedContext etc into a shared fixtures dir so that it can be used for both rollupcontext tests _and_ createFilter tests - in my stylistic opinion, I prefer to put nearly _all_ consts like these into fixtures dir - configure jest to ignore test helpers in coverage reporting such as fixture files - format: '' -> "", add semicolon in some places - I use single quotes and no semicolons, so missed that in a few places - lint didn't check for that and no prettier auto-format :/
- Loading branch information
Showing
4 changed files
with
97 additions
and
55 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,51 @@ | ||
import { PluginContext } from "rollup"; | ||
|
||
import { IContext } from "../../src/context"; | ||
|
||
const stub = (x: any) => x; | ||
|
||
const contextualLogger = (data: any): IContext => { | ||
return { | ||
warn: (x: any) => { | ||
data.warn = x; | ||
}, | ||
error: (x: any) => { | ||
data.error = x; | ||
}, | ||
info: (x: any) => { | ||
data.info = x; | ||
}, | ||
debug: (x: any) => { | ||
data.debug = x; | ||
}, | ||
}; | ||
}; | ||
|
||
export function makeStubbedContext (data: any): PluginContext & IContext { | ||
const { warn, error, info, debug } = contextualLogger(data); | ||
return { | ||
addWatchFile: stub as any, | ||
getWatchFiles: stub as any, | ||
cache: stub as any, | ||
load: stub as any, | ||
resolve: stub as any, | ||
resolveId: stub as any, | ||
isExternal: stub as any, | ||
meta: stub as any, | ||
emitAsset: stub as any, | ||
emitChunk: stub as any, | ||
emitFile: stub as any, | ||
setAssetSource: stub as any, | ||
getAssetFileName: stub as any, | ||
getChunkFileName: stub as any, | ||
getFileName: stub as any, | ||
parse: stub as any, | ||
warn: warn as any, | ||
error: error as any, | ||
info: info as any, | ||
debug: debug as any, | ||
moduleIds: stub as any, | ||
getModuleIds: stub as any, | ||
getModuleInfo: stub as any | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
/** @type {import('@jest/types').Config.InitialOptions} */ | ||
/** @type {import("@jest/types").Config.InitialOptions} */ | ||
const config = { | ||
preset: 'ts-jest', | ||
preset: "ts-jest", | ||
injectGlobals: false, // use @jest/globals instead | ||
restoreMocks: true, | ||
// only use *.spec.ts files in __tests__, no auto-generated files | ||
testMatch: ["**/__tests__/**/*.spec.ts?(x)"] | ||
testMatch: ["**/__tests__/**/*.spec.ts?(x)"], | ||
coveragePathIgnorePatterns: [ | ||
"node_modules", // default | ||
"<rootDir>/__tests__/" // ignore any test helper files | ||
], | ||
}; | ||
|
||
module.exports = config; |