Skip to content

Commit

Permalink
Fix project selection after basename addition (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeliog authored Sep 20, 2018
1 parent 94b7fc6 commit e42e9cd
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,45 @@ class JestPluginProjects {

apply(jestHook) {
jestHook.onFileChange(({ projects }) => this._setProjects(projects));
jestHook.shouldRunTestSuite(
({ testPath, config: { displayName } }) =>
displayName === undefined ||
this._activeProjects[displayName] === undefined ||
this._activeProjects[displayName],
);
jestHook.shouldRunTestSuite(({ testPath, config }) => {
const name = config.displayName || path.basename(config.rootDir);
return (
this._activeProjects[name] === undefined || this._activeProjects[name]
);
});
}

onKey() {}

_setProjects(projects) {
if (!this._projectNames.length) {
const projectNameSet = projects.reduce(
(state, p) => {
const { displayName, rootDir } = p.config;
if (state.has(displayName)) {
throw new Error(`
const projectNameSet = projects.reduce((state, p) => {
const { displayName, rootDir } = p.config;
if (state.has(displayName)) {
throw new Error(`
Found multiple projects with the same \`displayName\`: "${displayName}"
Change the \`displayName\` on at least one of them to prevent name collision.
- More info: https://facebook.github.io/jest/docs/en/configuration.html#projects-array-string-projectconfig
`);
}
}

const basename = path.basename(rootDir);
if (state.has(basename)) {
throw new Error(`
const basename = path.basename(rootDir);
if (state.has(basename)) {
throw new Error(`
Found multiple projects with the same directory basename: "${basename}"
Add a \`displayName\` to at least one of them to prevent name collision.
- More info: https://facebook.github.io/jest/docs/en/configuration.html#projects-array-string-projectconfig
`);
}
}

return new Set([...state, displayName || basename]);
},
new Set()
);
return new Set([...state, displayName || basename]);
}, new Set());

this._projectNames = [...projectNameSet];
this._setActiveProjects(this._projectNames);
Expand Down

0 comments on commit e42e9cd

Please sign in to comment.