Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jul 5, 2021
1 parent e679173 commit 7a6c4fa
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 167 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function hasTypeModule (path) {
let root = pathResolve('/');
while ((path = pathResolve(path, '..')) !== root) {
try {
return JSON.parse(fs.readFileSync(pathResolve(path, 'package.json')).toString()).type === 'module';
return JSON.parse(fs.readFileSync(eval('pathResolve')(path, 'package.json')).toString()).type === 'module';
}
catch (e) {
if (e.code === 'ENOENT')
Expand All @@ -50,9 +50,9 @@ function ncc (
{
cache,
customEmit = undefined,
esm = entry.endsWith('.mjs') || !entry.endsWith('.cjs') && hasTypeModule(pathResolve(entry)),
esm = entry.endsWith('.mjs') || !entry.endsWith('.cjs') && hasTypeModule(entry),
externals = [],
filename = 'index' + (!esm && entry.endsWith('.cjs') ? '.cjs' : hasTypeModule(pathResolve(entry)) ? '.js' : '.mjs'),
filename = 'index' + (!esm && entry.endsWith('.cjs') ? '.cjs' : !esm || hasTypeModule(entry) ? '.js' : '.mjs'),
minify = false,
sourceMap = false,
sourceMapRegister = true,
Expand Down Expand Up @@ -92,7 +92,7 @@ function ncc (

if (!quiet) {
console.log(`ncc: Version ${nccVersion}`);
console.log(`ncc: Compiling file ${filename} as ${esm ? 'ESM' : 'CJS'}`);
console.log(`ncc: Compiling file ${filename} into ${esm ? 'ESM' : 'CJS'}`);
}

if (target && !target.startsWith('es')) {
Expand Down Expand Up @@ -252,7 +252,7 @@ function ncc (
amd: false,
experiments: {
topLevelAwait: true,
outputModule: true
outputModule: esm
},
optimization: {
nodeEnv: false,
Expand Down
32 changes: 5 additions & 27 deletions test/unit/exports-nomodule/output-coverage.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ "use strict";
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__nccwpck_require__.r(__webpack_exports__);

;// CONCATENATED MODULE: ./test/unit/exports-nomodule/node.js
var x = 'x';

;// CONCATENATED MODULE: ./test/unit/exports-nomodule/input.js

console.log(x);

module.exports = __webpack_exports__;
/******/ })()
;
console.log(x);
32 changes: 5 additions & 27 deletions test/unit/exports-nomodule/output.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ "use strict";
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__nccwpck_require__.r(__webpack_exports__);

;// CONCATENATED MODULE: ./test/unit/exports-nomodule/node.js
var x = 'x';

;// CONCATENATED MODULE: ./test/unit/exports-nomodule/input.js

console.log(x);

module.exports = __webpack_exports__;
/******/ })()
;
console.log(x);
32 changes: 5 additions & 27 deletions test/unit/exports-wildcard/output-coverage.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ "use strict";
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__nccwpck_require__.r(__webpack_exports__);

;// CONCATENATED MODULE: ./test/unit/exports-wildcard/node.js
var y = 'y';

;// CONCATENATED MODULE: ./test/unit/exports-wildcard/input.js

console.log(y);

module.exports = __webpack_exports__;
/******/ })()
;
console.log(y);
32 changes: 5 additions & 27 deletions test/unit/exports-wildcard/output.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ "use strict";
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__nccwpck_require__.r(__webpack_exports__);

;// CONCATENATED MODULE: ./test/unit/exports-wildcard/node.js
var y = 'y';

;// CONCATENATED MODULE: ./test/unit/exports-wildcard/input.js

console.log(y);

module.exports = __webpack_exports__;
/******/ })()
;
console.log(y);
32 changes: 5 additions & 27 deletions test/unit/imports/output-coverage.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ "use strict";
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__nccwpck_require__.r(__webpack_exports__);

;// CONCATENATED MODULE: ./test/unit/imports/node.js
var x = 'x';

;// CONCATENATED MODULE: ./test/unit/imports/input.js

console.log(x);

module.exports = __webpack_exports__;
/******/ })()
;
console.log(x);
32 changes: 5 additions & 27 deletions test/unit/imports/output.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __nccwpck_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ "use strict";
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__nccwpck_require__.r(__webpack_exports__);

;// CONCATENATED MODULE: ./test/unit/imports/node.js
var x = 'x';

;// CONCATENATED MODULE: ./test/unit/imports/input.js

console.log(x);

module.exports = __webpack_exports__;
/******/ })()
;
console.log(x);

0 comments on commit 7a6c4fa

Please sign in to comment.