Skip to content

Commit

Permalink
test(core): add draft version of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bhovhannes committed Nov 30, 2021
1 parent 51b470e commit 42cd041
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const rd = require('react-dom')
const {upperCase} = require('lodash')

console.log(rd)
console.log(upperCase('foo'))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const {upperCase} = require('lodash')

function lodash(s) {
console.log(s)
}
lodash(upperCase('foo'))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import _ from 'lodash';

console.log(_.upperCase('hello world '))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LuckySeven = 777
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as lodashAll from 'lodash';

console.log(lodashAll.upperCase('hello world '))
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "amd",
"private": true,
"main": "dist/index.js",
"dependencies": {
"lodash": "^4.17.11",
"react": "^16.11.0",
"react-dom": "^16.11.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
document.querySelector('button').addEventListener('click', () => {
import('./exports.js').then(module => {
console.log(module)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { upperCase, kebabCase } from 'lodash';
import { render } from 'react-dom';
import 'react';

render(document.getElementById('app'), function App() {
return upperCase('hello world ') + kebabCase('from Kevin and Stuart and Bob')
})
250 changes: 250 additions & 0 deletions packages/core/integration-tests/test/output-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,256 @@ const bundle = (name, opts = {}) => {
};

describe('output formats', function () {
describe('amd', function () {
it('should support named exports', async function () {
let b = await bundle(
path.join(__dirname, '/integration/formats/amd/exports.js'),
{
targets: {
main: {
isLibrary: true,
outputFormat: 'amd',
distDir: 'dist',
sourceMap: false,
},
},
},
);

let dist = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert.equal(
dist,
`define(["exports"], function ($b3d6c7cfe613c4d4$exports) {
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export($b3d6c7cfe613c4d4$exports, "LuckySeven", function () { return $b3d6c7cfe613c4d4$export$bd99680d3ec8853; });
var $b3d6c7cfe613c4d4$export$bd99680d3ec8853 = 777;
});
`,
);
});

it('should support default exports', async function () {
let b = await bundle(
path.join(__dirname, '/integration/formats/amd/default-export.js'),
{
targets: {
main: {
isLibrary: true,
outputFormat: 'amd',
distDir: 'dist',
sourceMap: false,
includeNodeModules: {
lodash: false,
},
},
},
},
);

let dist = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert.equal(
dist,
`define(["exports","lodash"], function ($1a80b16607b7544e$exports, $1a80b16607b7544e$arg1) {
var $4kW22$lodash = $1a80b16607b7544e$arg1['default'];
console.log($4kW22$lodash.upperCase('hello world '));
});
`,
);
});

it('should support import star', async function () {
let b = await bundle(
path.join(__dirname, '/integration/formats/amd/import-star.js'),
{
targets: {
main: {
isLibrary: true,
outputFormat: 'amd',
distDir: 'dist',
sourceMap: false,
includeNodeModules: {
lodash: false,
},
},
},
},
);

let dist = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert.equal(
dist,
`define(["exports","lodash"], function ($2bad6c833260d97f$exports, $2bad6c833260d97f$arg1) {
var $2s5ZT$upperCase = $2bad6c833260d97f$arg1['upperCase'];
console.log($2s5ZT$upperCase('hello world '));
});
`,
);
});

it('should support CommonJS require', async function () {
let b = await bundle(
path.join(__dirname, '/integration/formats/amd/cjs-require.js'),
{
targets: {
main: {
isLibrary: true,
outputFormat: 'amd',
distDir: 'dist',
sourceMap: false,
includeNodeModules: {
lodash: false,
'react-dom': false,
},
},
},
},
);

let dist = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert.equal(
dist,
`define(["exports","react-dom","lodash"], function ($113a60fdf450e4ed$exports, $lQGmL$reactdom, $113a60fdf450e4ed$arg2) {
var $lQGmL$upperCase = $113a60fdf450e4ed$arg2['upperCase'];
var $113a60fdf450e4ed$require$upperCase = $lQGmL$upperCase;
console.log($lQGmL$reactdom);
console.log($113a60fdf450e4ed$require$upperCase('foo'));
});
`,
);
});

it('should handle names correctly', async function () {
let b = await bundle(
path.join(__dirname, '/integration/formats/amd/conflicting-names.js'),
{
targets: {
main: {
isLibrary: true,
outputFormat: 'amd',
distDir: 'dist',
sourceMap: false,
includeNodeModules: {
lodash: false,
},
},
},
},
);

let dist = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert.equal(
dist,
`define(["exports","lodash"], function ($2b6cf5ae299cafa7$exports, $2b6cf5ae299cafa7$arg1) {
var $kxDD2$upperCase = $2b6cf5ae299cafa7$arg1['upperCase'];
var $2b6cf5ae299cafa7$require$upperCase = $kxDD2$upperCase;
function $2b6cf5ae299cafa7$var$lodash(s) {
console.log(s);
}
$2b6cf5ae299cafa7$var$lodash($2b6cf5ae299cafa7$require$upperCase('foo'));
});
`,
);
});

it('should support external dependencies', async function () {
let b = await bundle(
path.join(__dirname, '/integration/formats/amd/with-external-deps.js'),
{
targets: {
main: {
isLibrary: true,
outputFormat: 'amd',
distDir: 'dist',
sourceMap: false,
includeNodeModules: {
lodash: false,
react: false,
'react-dom': false,
},
},
},
},
);

let dist = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert.equal(
dist,
`define(["exports","lodash","react-dom","react"], function ($4af9a3a646d1cc86$exports, $4af9a3a646d1cc86$arg1, $4af9a3a646d1cc86$arg2, $4af9a3a646d1cc86$arg3) {
var $9Ujeu$upperCase = $4af9a3a646d1cc86$arg1['upperCase'];
var $9Ujeu$kebabCase = $4af9a3a646d1cc86$arg1['kebabCase'];
var $9Ujeu$render = $4af9a3a646d1cc86$arg2['render'];
$9Ujeu$render(document.getElementById('app'), function App() {
return $9Ujeu$upperCase('hello world ') + $9Ujeu$kebabCase('from Kevin and Stuart and Bob');
});
});
`,
);
});

// it('should support dynamic imports', async function() {
// let b = await bundle(
// path.join(__dirname, '/integration/formats/amd/with-dynamic-import.js'),
// {
// targets: {
// main: {
// isLibrary: true,
// outputFormat: "amd",
// distDir: 'dist',
// sourceMap: false,
// }
// }
// }
// );
//
// assert.equal(b.getBundles().length, 2)
// let mainChunk = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
// assert(mainChunk.includes('require('))
//
// let lazyChunk = await outputFS.readFile(b.getBundles()[1].filePath, 'utf8');
// assert.equal(lazyChunk, `define(["exports"], function ($b3d6c7cfe613c4d4$exports) {
// function $parcel$export(e, n, v, s) {
// Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
// }
// var $parcel$global =
// typeof globalThis !== 'undefined'
// ? globalThis
// : typeof self !== 'undefined'
// ? self
// : typeof window !== 'undefined'
// ? window
// : typeof global !== 'undefined'
// ? global
// : {};
// var parcelRequire = $parcel$global["parcelRequire94c2"];
// parcelRequire.register("frhhl", function(module, exports) {
//
// $parcel$export(module.exports, "LuckySeven", function () { return $b3d6c7cfe613c4d4$export$bd99680d3ec8853; });
// var $b3d6c7cfe613c4d4$export$bd99680d3ec8853 = 777;
//
// });
//
// });
// `)
// });
});

describe('commonjs', function () {
it('should support commonjs output (exports)', async function () {
let b = await bundle(
Expand Down

0 comments on commit 42cd041

Please sign in to comment.