Skip to content

Commit

Permalink
Merge branch 'master' into fix/pragma-frag
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper committed Feb 8, 2019
2 parents aedece5 + f23c844 commit ba355f6
Show file tree
Hide file tree
Showing 82 changed files with 1,545 additions and 1,299 deletions.
7 changes: 6 additions & 1 deletion packages/core/integration-tests/test/bundler.js
@@ -1,7 +1,12 @@
const assert = require('assert');
const sinon = require('sinon');
const path = require('path');
const {assertBundleTree, bundle, bundler, nextBundle} = require('./utils');
const {
assertBundleTree,
bundle,
bundler,
nextBundle
} = require('@parcel/test-utils');

describe('bundler', function() {
it('should bundle once before exporting middleware', async function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/contentHashing.js
@@ -1,7 +1,7 @@
const assert = require('assert');
const path = require('path');
const fs = require('@parcel/fs');
const {bundle, rimraf, ncp} = require('./utils');
const {bundle, rimraf, ncp} = require('@parcel/test-utils');

describe('content hashing', function() {
beforeEach(async function() {
Expand Down
56 changes: 55 additions & 1 deletion packages/core/integration-tests/test/css.js
@@ -1,7 +1,13 @@
const assert = require('assert');
const path = require('path');
const fs = require('@parcel/fs');
const {bundle, run, assertBundleTree, rimraf, ncp} = require('./utils');
const {
bundle,
run,
assertBundleTree,
rimraf,
ncp
} = require('@parcel/test-utils');

describe('css', function() {
it('should produce two bundles when importing a CSS file', async function() {
Expand Down Expand Up @@ -213,6 +219,54 @@ describe('css', function() {
);
});

it('should support linking to assets in parent folders with url() from CSS', async function() {
let b = await bundle(
[
path.join(__dirname, '/integration/css-url-relative/src/a/style1.css'),
path.join(__dirname, '/integration/css-url-relative/src/b/style2.css')
],
{
production: true,
sourceMaps: false
}
);

await assertBundleTree(b, [
{
type: 'css',
assets: ['style1.css'],
childBundles: [
{
type: 'png'
}
]
},
{
type: 'css',
assets: ['style2.css']
}
]);

let css = await fs.readFile(
path.join(__dirname, '/dist/a/style1.css'),
'utf8'
);

assert(css.includes('background-image'), 'includes `background-image`');
assert(/url\([^)]*\)/.test(css), 'includes url()');

assert(
await fs.exists(
path.join(
__dirname,
path.dirname('/dist/a/style1.css'),
css.match(/url\(([^)]*)\)/)[1]
)
),
'path specified in url() exists'
);
});

it('should support transforming with postcss', async function() {
let b = await bundle(path.join(__dirname, '/integration/postcss/index.js'));

Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/elm.js
@@ -1,6 +1,6 @@
const assert = require('assert');
const fs = require('@parcel/fs');
const {bundle, assertBundleTree, run} = require('./utils');
const {bundle, assertBundleTree, run} = require('@parcel/test-utils');

describe('elm', function() {
it('should produce a basic Elm bundle', async function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/encodedURI.js
@@ -1,7 +1,7 @@
const assert = require('assert');
const path = require('path');
const fs = require('@parcel/fs');
const {bundle, assertBundleTree} = require('./utils');
const {bundle, assertBundleTree} = require('@parcel/test-utils');

describe('encodedURI', function() {
it('should support bundling files which names in encoded URI', async function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/fs.js
@@ -1,7 +1,7 @@
const assert = require('assert');
const fs = require('@parcel/fs');
const path = require('path');
const {bundle, run, assertBundleTree} = require('./utils');
const {bundle, run, assertBundleTree} = require('@parcel/test-utils');

describe('fs', function() {
describe('--target=browser', function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/glob.js
@@ -1,7 +1,7 @@
const assert = require('assert');
const fs = require('@parcel/fs');
const path = require('path');
const {bundle, run, assertBundleTree} = require('./utils');
const {bundle, run, assertBundleTree} = require('@parcel/test-utils');

describe('glob', function() {
it('should require a glob of files', async function() {
Expand Down
7 changes: 6 additions & 1 deletion packages/core/integration-tests/test/glsl.js
@@ -1,7 +1,12 @@
const assert = require('assert');
const path = require('path');
const fs = require('@parcel/fs');
const {bundle, run, assertBundleTree, normaliseNewlines} = require('./utils');
const {
bundle,
run,
assertBundleTree,
normaliseNewlines
} = require('@parcel/test-utils');

describe('glsl', function() {
it('should support requiring GLSL files via glslify', async function() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/graphql.js
@@ -1,7 +1,7 @@
const assert = require('assert');
const path = require('path');
const gql = require('graphql-tag');
const {bundle, run, assertBundleTree} = require('./utils');
const {bundle, run, assertBundleTree} = require('@parcel/test-utils');

describe('graphql', function() {
it('should support requiring graphql files', async function() {
Expand Down
54 changes: 53 additions & 1 deletion packages/core/integration-tests/test/hmr.js
@@ -1,7 +1,7 @@
const assert = require('assert');
const fs = require('@parcel/fs');
const path = require('path');
const {bundler, run, rimraf, ncp} = require('./utils');
const {bundler, run, rimraf, ncp} = require('@parcel/test-utils');
const {sleep} = require('@parcel/test-utils');
const WebSocket = require('ws');
const json5 = require('json5');
Expand Down Expand Up @@ -529,4 +529,56 @@ describe('hmr', function() {

await buildEnd;
});

it('should watch new dependencies that cause errors', async function() {
await ncp(
path.join(__dirname, '/integration/elm-dep-error'),
path.join(__dirname, '/input')
);

b = bundler(path.join(__dirname, '/input/index.js'), {
watch: true,
hmr: true
});
await b.bundle();

ws = new WebSocket('ws://localhost:' + b.options.hmrPort);

const buildEnd = nextEvent(b, 'buildEnd');

await sleep(100);
fs.writeFile(
path.join(__dirname, '/input/src/Main.elm'),
`
module Main exposing (main)
import BrokenDep
import Html
main =
Html.text "Hello, world!"
`
);

let msg = JSON.parse(await nextEvent(ws, 'message'));
assert.equal(msg.type, 'error');

await sleep(100);
fs.writeFile(
path.join(__dirname, '/input/src/BrokenDep.elm'),
`
module BrokenDep exposing (anError)
anError : String
anError =
"fixed"
`
);

msg = JSON.parse(await nextEvent(ws, 'message'));
assert.equal(msg.type, 'error-resolved');

await buildEnd;
});
});
54 changes: 37 additions & 17 deletions packages/core/integration-tests/test/html.js
@@ -1,6 +1,6 @@
const assert = require('assert');
const fs = require('@parcel/fs');
const {bundle, assertBundleTree} = require('./utils');
const {bundle, assertBundleTree} = require('@parcel/test-utils');
const path = require('path');

describe('html', function() {
Expand Down Expand Up @@ -280,16 +280,32 @@ describe('html', function() {
});

it('should minify HTML in production mode', async function() {
await bundle(path.join(__dirname, '/integration/htmlnano/index.html'), {
let inputFile = path.join(__dirname, '/integration/htmlnano/index.html');
await bundle(inputFile, {
production: true
});

let html = await fs.readFile(
path.join(__dirname, '/dist/index.html'),
'utf8'
);
let inputSize = (await fs.stat(inputFile)).size;

let outputFile = path.join(__dirname, '/dist/index.html');
let outputSize = (await fs.stat(outputFile)).size;

assert(inputSize > outputSize);

let html = await fs.readFile(outputFile, 'utf8');
assert(html.includes('Other page'));
assert(!html.includes('\n'));
});

it('should work with an empty html file', async function() {
let inputFile = path.join(__dirname, '/integration/html-empty/index.html');
await bundle(inputFile, {
minify: false
});

let outputFile = path.join(__dirname, '/dist/index.html');

let html = await fs.readFile(outputFile, 'utf8');
assert.equal(html.length, 0);
});

it('should read .htmlnanorc and minify HTML in production mode', async function() {
Expand Down Expand Up @@ -326,19 +342,23 @@ describe('html', function() {
});

it('should not minify default values inside HTML in production mode', async function() {
await bundle(
path.join(__dirname, '/integration/htmlnano-defaults-form/index.html'),
{
production: true
}
let inputFile = path.join(
__dirname,
'/integration/htmlnano-defaults-form/index.html'
);
await bundle(inputFile, {
production: true
});

let html = await fs.readFile(
path.join(__dirname, '/dist/index.html'),
'utf8'
);
let inputSize = (await fs.stat(inputFile)).size;

let outputFile = path.join(__dirname, '/dist/index.html');
let outputSize = (await fs.stat(outputFile)).size;

assert(inputSize > outputSize);

let html = await fs.readFile(outputFile, 'utf8');
assert(html.includes('<input type="text">'));
assert(!html.includes('\n'));
});

it('should not prepend the public path to assets with remote URLs', async function() {
Expand Down
@@ -0,0 +1,3 @@
body {
background-image: url('../foo.png');
}
@@ -0,0 +1,3 @@
body {
color: red;
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,24 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.0",
"elm/core": "1.0.0",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.0.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
@@ -0,0 +1,5 @@
var local = require('./src/Main.elm');

module.exports = function () {
return local;
};
@@ -0,0 +1,8 @@
module BrokenDep exposing (anError)

{- This module causes a compiler error -}


anError : String
anError =
2
@@ -0,0 +1,7 @@
module Main exposing (main)

import Html


main =
Html.text "Hello, world!"
Expand Up @@ -2,7 +2,7 @@ module.exports = function () {
return {
dir: __dirname,
file: __filename,
buf: new Buffer(process.title).toString('base64'),
buf: Buffer.from(process.title).toString('base64'),
global: !!global.document
};
};
Empty file.
@@ -0,0 +1,3 @@
import * as Hyperapp from 'hyperapp'

module.exports = <div />;
@@ -0,0 +1,3 @@
{
"private": true
}
@@ -0,0 +1,3 @@
import * as Nerv from 'nervjs';

module.exports = <div />;
@@ -0,0 +1,3 @@
{
"private": true
}
@@ -0,0 +1,3 @@
const Preact = require('preact');

module.exports = <div />;
@@ -0,0 +1,3 @@
{
"private": true
}
@@ -0,0 +1,3 @@
import * as React from 'react';

module.exports = <div />;
@@ -0,0 +1,3 @@
{
"private": true
}

0 comments on commit ba355f6

Please sign in to comment.