Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
feat: Add moduleNameMapper method
Browse files Browse the repository at this point in the history
This method is required to configure jest.
  • Loading branch information
Romakita committed Jul 6, 2018
1 parent dbb04a3 commit 1b804eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/config.js
Expand Up @@ -165,7 +165,7 @@ class Config {
* @returns {*}
*/
get foundationScriptsRoot() {
return formatPath(path.join(this.get('foundationRoot'), this.get('foundationScriptsRoot')));
return formatPath(`./${path.join(this.get('foundationRoot'), this.get('foundationScriptsRoot'))}`);
}

/**
Expand Down Expand Up @@ -209,6 +209,15 @@ class Config {
};
}

get moduleNameMapper() {
return {
'^@Foundation(.*)$': `${this.foundationScriptsRoot.replace('./', '<rootDir>/')}$1`,
'^@Feature(.*)$': `${this.featureRoot.replace('./', '<rootDir>/')}$1`,
'^@Project(.*)$': `${this.projectRoot.replace('./', '<rootDir>/')}$1`,
'^@/(.*)$': `${this.srcRoot.replace('./', '<rootDir>/')}/$1`
};
}

/**
*
* @returns {*}
Expand Down
11 changes: 10 additions & 1 deletion test/unit/config.spec.js
Expand Up @@ -129,7 +129,7 @@ describe('Config', () => {
});

it('should return foundationScriptsRoot', () => {
expect(config.foundationScriptsRoot).to.contains(formatPath('src/Foundation/Core/code/Scripts'));
expect(config.foundationScriptsRoot).to.contains(formatPath('./src/Foundation/Core/code/Scripts'));
});

it('should return featureRoot', () => {
Expand Down Expand Up @@ -172,5 +172,14 @@ describe('Config', () => {
styleguide: 'styleguide'
});
});

it('should return moduleNameMapper object', () => {
expect(config.moduleNameMapper).to.deep.eq({
'^@/(.*)$': '<rootDir>/src/$1',
'^@Feature(.*)$': '<rootDir>/src/Feature$1',
'^@Foundation(.*)$': '<rootDir>/src/Foundation/Core/code/Scripts$1',
'^@Project(.*)$': '<rootDir>/src/Project$1'
});
});
});
});

0 comments on commit 1b804eb

Please sign in to comment.