Skip to content

Commit

Permalink
fix displayName object configuration (#8)
Browse files Browse the repository at this point in the history
* prettier config

* support displayName object configuration
  • Loading branch information
jeysal authored and rogeliog committed Jun 25, 2019
1 parent b446843 commit f87a76c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit f87a76c

Please sign in to comment.