Skip to content

Commit 53998f5

Browse files
committed
fix(test): fix jest reporter config
Closes #1160
1 parent ed282b9 commit 53998f5

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/testing/jest/jest-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export function buildJestConfig(config: d.Config) {
3939

4040
jestConfig.rootDir = config.rootDir;
4141

42+
if (Array.isArray(config.testing.reporters)) {
43+
jestConfig.reporters = config.testing.reporters;
44+
}
45+
4246
return JSON.stringify(jestConfig);
4347
}
4448

src/testing/jest/test/jest-config.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ describe('jest-config', () => {
102102
expect(parsedConfig.testMatch).toEqual(['hello.spec.ts']);
103103
});
104104

105+
it('set jestArgv config reporters', () => {
106+
const rootDir = path.resolve('/');
107+
const process: any = {
108+
argv: ['node stencil test']
109+
};
110+
const config = new TestingConfig();
111+
config.rootDir = rootDir;
112+
config.flags = parseFlags(process);
113+
config.testing = {
114+
reporters: [
115+
'default',
116+
['jest-junit', { suiteName: 'jest tests' } ]
117+
]
118+
};
119+
120+
const jestArgv = buildJestArgv(config);
121+
const parsedConfig = JSON.parse(jestArgv.config) as d.JestConfig;
122+
expect(parsedConfig.reporters).toHaveLength(2);
123+
expect(parsedConfig.reporters[0]).toBe('default');
124+
expect(parsedConfig.reporters[1][0]).toBe('jest-junit');
125+
expect(parsedConfig.reporters[1][1].suiteName).toBe('jest tests');
126+
});
127+
105128
it('set jestArgv config rootDir', () => {
106129
const rootDir = path.resolve('/');
107130
const process: any = {

test/example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@types/puppeteer": "1.6.4",
1212
"jest": "23.6.0",
1313
"jest-cli": "23.6.0",
14+
"jest-junit": "^5.2.0",
1415
"puppeteer": "1.8.0",
1516
"workbox-build": "3.4.1"
1617
}

test/example/stencil.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const config: Config = {
88
],
99

1010
testing: {
11-
// testRegex: ''
11+
reporters: ['default', ['jest-junit', { output: 'www/junit.xml' }]]
1212
}
1313

1414
};

0 commit comments

Comments
 (0)