Skip to content

Commit

Permalink
(test): ensure tsdx.config.js w/ rollup-plugin-postcss works
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Mar 27, 2020
1 parent 7617726 commit 1e690b5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* ::placeholder should be autoprefixed, and everything minified */
.test::placeholder {
color: 'blue';
}
2 changes: 2 additions & 0 deletions test/integration-tests/fixtures/build-withConfig/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './index.css';

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
Expand Down
64 changes: 64 additions & 0 deletions test/integration-tests/tsdx-build-withConfig.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 1e690b5

Please sign in to comment.