Skip to content

Commit

Permalink
Add tests for autoinstalling packages
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Dec 22, 2017
1 parent 7b80953 commit bc90871
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/css.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const assert = require('assert');
const fs = require('fs');
const {bundle, run, assertBundleTree} = require('./utils');
const promisify = require('../src/utils/promisify');
const ncp = promisify(require('ncp'));
const rimraf = require('rimraf');

describe('css', function() {
it('should produce two bundles when importing a CSS file', async function() {
Expand Down Expand Up @@ -161,4 +164,38 @@ describe('css', function() {
assert(css.includes('.index'));
assert(!css.includes('\n'));
});

it('should automatically install postcss plugins with npm if needed', async function() {
rimraf.sync(__dirname + '/input');
await ncp(__dirname + '/integration/autoinstall/npm', __dirname + '/input');
await bundle(__dirname + '/input/index.css');

// cssnext was installed
let package = require('./input/package.json');
assert(package.devDependencies['postcss-cssnext']);

// cssnext is applied
let css = fs.readFileSync(__dirname + '/dist/index.css', 'utf8');
assert(css.includes('rgba'));
});

it('should automatically install postcss plugins with yarn if needed', async function() {
rimraf.sync(__dirname + '/input');
await ncp(
__dirname + '/integration/autoinstall/yarn',
__dirname + '/input'
);
await bundle(__dirname + '/input/index.css');

// cssnext was installed
let package = require('./input/package.json');
assert(package.devDependencies['postcss-cssnext']);

let lockfile = fs.readFileSync(__dirname + '/input/yarn.lock', 'utf8');
assert(lockfile.includes('postcss-cssnext'));

// cssnext is applied
let css = fs.readFileSync(__dirname + '/dist/index.css', 'utf8');
assert(css.includes('rgba'));
});
});
5 changes: 5 additions & 0 deletions test/integration/autoinstall/npm/.postcssrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": {
"postcss-cssnext": true
}
}
3 changes: 3 additions & 0 deletions test/integration/autoinstall/npm/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test {
background: #9d9c;
}
3 changes: 3 additions & 0 deletions test/integration/autoinstall/npm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "parcel-test-autoinstall-npm"
}
5 changes: 5 additions & 0 deletions test/integration/autoinstall/yarn/.postcssrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": {
"postcss-cssnext": true
}
}
3 changes: 3 additions & 0 deletions test/integration/autoinstall/yarn/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test {
background: #9d9c;
}
3 changes: 3 additions & 0 deletions test/integration/autoinstall/yarn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "parcel-test-autoinstall-yarn"
}
Empty file.

0 comments on commit bc90871

Please sign in to comment.