diff --git a/test/integration/tsdx-build-withBabel.test.js b/test/integration/tsdx-build-withBabel.test.js index 72b93a1aa..391f2191e 100644 --- a/test/integration/tsdx-build-withBabel.test.js +++ b/test/integration/tsdx-build-withBabel.test.js @@ -15,28 +15,28 @@ describe('integration :: tsdx build :: .babelrc.js', () => { }); it('should convert styled-components template tags', () => { - let output = shell.exec('node ../dist/index.js build'); + const output = shell.exec('node ../dist/index.js build'); expect(output.code).toBe(0); // from styled.h1` to styled.h1( - output = shell.grep(/styled.h1\(/, ['dist/build-withbabel.*.js']); - expect(output.code).toBe(0); + const matched = util.grep(/styled.h1\(/, ['dist/build-withbabel.*.js']); + expect(matched).toBeTruthy(); }); // TODO: make this test work by allowing customization of plugin order it.skip('should remove comments in the CSS', () => { // the "should be removed" comment shouldn't be there (gets error code) - const output = shell.grep(/should be removed/, [ + const matched = util.grep(/should be removed/, [ 'dist/build-withbabel.*.js', ]); - expect(output.code).toBe(1); + expect(matched).toBeTruthy(); }); it('should add an import of regeneratorRuntime', () => { - const output = shell.grep(/@babel\/runtime\/regenerator/, [ + const matched = util.grep(/@babel\/runtime\/regenerator/, [ 'dist/build-withbabel.*.js', ]); - expect(output.code).toBe(0); + expect(matched).toBeTruthy(); }); it('should compile files into a dist directory', () => { diff --git a/test/util.js b/test/util.js index df4145df9..13b5fcbd7 100644 --- a/test/util.js +++ b/test/util.js @@ -4,6 +4,18 @@ const rootDir = process.cwd(); shell.config.silent = true; +// shelljs.grep wrapper +// @param {RegExp} pattern +// @param {string} fileName +// @returns {boolean} true if pattern has matches in file +function grep(pattern, fileName) { + const output = shell.grep(pattern, fileName); + // output.code is always 0 regardless of matched/unmatched patterns + // so need to test output.stdout + // https://github.com/jaredpalmer/tsdx/pull/525#discussion_r395571779 + return Boolean(output.stdout.match(pattern)); +} + module.exports = { setupStageWithFixture: (testDir, stageName, fixtureName) => { const stagePath = path.join(rootDir, stageName); @@ -24,5 +36,6 @@ module.exports = { shell.rm('-rf', path.join(rootDir, stageName)); }, + grep, rootDir, };