Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix displayName object configuration #8

Merged
merged 2 commits into from Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -40,5 +40,9 @@
"execa": "0.8.0",
"jest": "23.0.1",
"prettier": "1.13.0"
},
"prettier": {
"singleQuote": true,
"trailingComma": "all"
}
}
17 changes: 14 additions & 3 deletions src/index.js
Expand Up @@ -13,7 +13,7 @@ class JestPluginProjects {
apply(jestHook) {
jestHook.onFileChange(({ projects }) => this._setProjects(projects));
jestHook.shouldRunTestSuite(({ testPath, config }) => {
const name = config.displayName || path.basename(config.rootDir);
const name = this._getDisplayName(config) || this._getBasename(config);
return (
this._activeProjects[name] === undefined || this._activeProjects[name]
);
Expand All @@ -22,10 +22,22 @@ class JestPluginProjects {

onKey() {}

_getDisplayName(config) {
const { displayName } = config;
return typeof displayName === 'object' ? displayName.name : displayName;
}

_getBasename(config) {
const { rootDir } = config;
return path.basename(rootDir);
}

_setProjects(projects) {
if (!this._projectNames.length) {
const projectNameSet = projects.reduce((state, p) => {
const { displayName, rootDir } = p.config;
const displayName = this._getDisplayName(p.config);
const basename = this._getBasename(p.config);

if (state.has(displayName)) {
throw new Error(`

Expand All @@ -37,7 +49,6 @@ Change the \`displayName\` on at least one of them to prevent name collision.
`);
}

const basename = path.basename(rootDir);
if (state.has(basename)) {
throw new Error(`

Expand Down