From 1e690b56dcfebcbc10cf3c544c422a150aabb690 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Wed, 18 Mar 2020 20:03:33 -0400 Subject: [PATCH] (test): ensure tsdx.config.js w/ rollup-plugin-postcss works - add and import a basic CSS file in build-withConfig - use the existing tsdx.config.js for the rollup config - ensure that one CSS file gets extracted at the end - ensure that it is properly autoprefixed and minifed too --- .../fixtures/build-withConfig/src/index.css | 4 ++ .../fixtures/build-withConfig/src/index.ts | 2 + .../tsdx-build-withConfig.test.js | 64 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 test/integration-tests/fixtures/build-withConfig/src/index.css create mode 100644 test/integration-tests/tsdx-build-withConfig.test.js diff --git a/test/integration-tests/fixtures/build-withConfig/src/index.css b/test/integration-tests/fixtures/build-withConfig/src/index.css new file mode 100644 index 000000000..51c83342c --- /dev/null +++ b/test/integration-tests/fixtures/build-withConfig/src/index.css @@ -0,0 +1,4 @@ +/* ::placeholder should be autoprefixed, and everything minified */ +.test::placeholder { + color: 'blue'; +} diff --git a/test/integration-tests/fixtures/build-withConfig/src/index.ts b/test/integration-tests/fixtures/build-withConfig/src/index.ts index af27ae37d..c0de22055 100644 --- a/test/integration-tests/fixtures/build-withConfig/src/index.ts +++ b/test/integration-tests/fixtures/build-withConfig/src/index.ts @@ -1,3 +1,5 @@ +import './index.css'; + export const sum = (a: number, b: number) => { if ('development' === process.env.NODE_ENV) { console.log('fuck'); diff --git a/test/integration-tests/tsdx-build-withConfig.test.js b/test/integration-tests/tsdx-build-withConfig.test.js new file mode 100644 index 000000000..a495293de --- /dev/null +++ b/test/integration-tests/tsdx-build-withConfig.test.js @@ -0,0 +1,64 @@ +const shell = require('shelljs'); +const fs = require('fs-extra'); + +const util = require('../utils/fixture'); +const { execWithCache } = require('../utils/shell'); + +shell.config.silent = false; + +const testDir = 'integration-tests'; +const fixtureName = 'build-withConfig'; +const stageName = `stage-integration-${fixtureName}`; + +describe('integration :: tsdx build :: tsdx.config.js', () => { + beforeAll(() => { + util.teardownStage(stageName); + util.setupStageWithFixture(testDir, stageName, fixtureName); + }); + + it('should create a CSS file in the dist/ directory', () => { + const output = execWithCache('node ../dist/index.js build'); + + // TODO: this is kind of subpar naming, rollup-plugin-postcss just names it + // the same as the output file, but with the .css extension + expect(shell.test('-f', 'dist/build-withconfig.cjs.development.css')); + + expect(output.code).toBe(0); + }); + + it('should autoprefix and minify the CSS file', async () => { + const output = execWithCache('node ../dist/index.js build'); + + const cssText = await fs.readFile( + './dist/build-withconfig.cjs.development.css' + ); + + // autoprefixed and minifed output + expect( + cssText.includes('.test::-webkit-input-placeholder{color:"blue"}') + ).toBeTruthy(); + + expect(output.code).toBe(0); + }); + + it('should compile files into a dist directory', () => { + const output = execWithCache('node ../dist/index.js build'); + + expect(shell.test('-f', 'dist/index.js')).toBeTruthy(); + expect( + shell.test('-f', 'dist/build-withconfig.cjs.development.js') + ).toBeTruthy(); + expect( + shell.test('-f', 'dist/build-withconfig.cjs.production.min.js') + ).toBeTruthy(); + expect(shell.test('-f', 'dist/build-withconfig.esm.js')).toBeTruthy(); + + expect(shell.test('-f', 'dist/index.d.ts')).toBeTruthy(); + + expect(output.code).toBe(0); + }); + + afterAll(() => { + util.teardownStage(stageName); + }); +});