From cbd84c5ee1aa2a509be7e536e902d1401d83bc9a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 20 Jan 2020 16:50:19 -0800 Subject: [PATCH] test,module: add test for exports cjs loader check Refs: https://github.com/nodejs/node/pull/31001#issuecomment-576353389 PR-URL: https://github.com/nodejs/node/pull/31427 Reviewed-By: Richard Lau Reviewed-By: Shelley Vohr Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott --- .../bluebird/js/release/bluebird.js | 0 .../node_modules/bluebird/package.json | 78 +++++++++++++++++++ test/fixtures/bluebird/package.json | 78 +++++++++++++++++++ test/fixtures/bluebird/test.js | 1 + .../test-require-invalid-main-no-exports.js | 20 +++++ 5 files changed, 177 insertions(+) create mode 100644 test/fixtures/bluebird/node_modules/bluebird/js/release/bluebird.js create mode 100644 test/fixtures/bluebird/node_modules/bluebird/package.json create mode 100644 test/fixtures/bluebird/package.json create mode 100644 test/fixtures/bluebird/test.js create mode 100644 test/parallel/test-require-invalid-main-no-exports.js diff --git a/test/fixtures/bluebird/node_modules/bluebird/js/release/bluebird.js b/test/fixtures/bluebird/node_modules/bluebird/js/release/bluebird.js new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/fixtures/bluebird/node_modules/bluebird/package.json b/test/fixtures/bluebird/node_modules/bluebird/package.json new file mode 100644 index 00000000000000..33f696cb246847 --- /dev/null +++ b/test/fixtures/bluebird/node_modules/bluebird/package.json @@ -0,0 +1,78 @@ +{ + "name": "bluebird", + "description": "Full featured Promises/A+ implementation with exceptionally good performance", + "version": "3.7.2", + "keywords": [ + "promise", + "performance", + "promises", + "promises-a", + "promises-aplus", + "async", + "await", + "deferred", + "deferreds", + "future", + "flow control", + "dsl", + "fluent interface" + ], + "scripts": { + "lint": "node scripts/jshint.js", + "test": "node --expose-gc tools/test.js", + "istanbul": "istanbul", + "prepublish": "npm run generate-browser-core && npm run generate-browser-full", + "generate-browser-full": "node tools/build.js --no-clean --no-debug --release --browser --minify", + "generate-browser-core": "node tools/build.js --features=core --no-debug --release --zalgo --browser --minify && mv js/browser/bluebird.js js/browser/bluebird.core.js && mv js/browser/bluebird.min.js js/browser/bluebird.core.min.js" + }, + "homepage": "https://github.com/petkaantonov/bluebird", + "repository": { + "type": "git", + "url": "git://github.com/petkaantonov/bluebird.git" + }, + "bugs": { + "url": "http://github.com/petkaantonov/bluebird/issues" + }, + "license": "MIT", + "author": { + "name": "Petka Antonov", + "email": "petka_antonov@hotmail.com", + "url": "http://github.com/petkaantonov/" + }, + "devDependencies": { + "acorn": "^6.0.2", + "acorn-walk": "^6.1.0", + "baconjs": "^0.7.43", + "bluebird": "^2.9.2", + "body-parser": "^1.10.2", + "browserify": "^8.1.1", + "cli-table": "~0.3.1", + "co": "^4.2.0", + "cross-spawn": "^0.2.3", + "glob": "^4.3.2", + "grunt-saucelabs": "~8.4.1", + "highland": "^2.3.0", + "istanbul": "^0.3.5", + "jshint": "^2.6.0", + "jshint-stylish": "~0.2.0", + "kefir": "^2.4.1", + "mkdirp": "~0.5.0", + "mocha": "~2.1", + "open": "~0.0.5", + "optimist": "~0.6.1", + "rimraf": "~2.2.6", + "rx": "^2.3.25", + "serve-static": "^1.7.1", + "sinon": "~1.7.3", + "uglify-js": "~2.4.16" + }, + "readmeFilename": "README.md", + "main": "./js/release/bluebird.js", + "webpack": "./js/release/bluebird.js", + "browser": "./js/browser/bluebird.js", + "files": [ + "js/browser", + "js/release", + "LICENSE" + ] +} diff --git a/test/fixtures/bluebird/package.json b/test/fixtures/bluebird/package.json new file mode 100644 index 00000000000000..33f696cb246847 --- /dev/null +++ b/test/fixtures/bluebird/package.json @@ -0,0 +1,78 @@ +{ + "name": "bluebird", + "description": "Full featured Promises/A+ implementation with exceptionally good performance", + "version": "3.7.2", + "keywords": [ + "promise", + "performance", + "promises", + "promises-a", + "promises-aplus", + "async", + "await", + "deferred", + "deferreds", + "future", + "flow control", + "dsl", + "fluent interface" + ], + "scripts": { + "lint": "node scripts/jshint.js", + "test": "node --expose-gc tools/test.js", + "istanbul": "istanbul", + "prepublish": "npm run generate-browser-core && npm run generate-browser-full", + "generate-browser-full": "node tools/build.js --no-clean --no-debug --release --browser --minify", + "generate-browser-core": "node tools/build.js --features=core --no-debug --release --zalgo --browser --minify && mv js/browser/bluebird.js js/browser/bluebird.core.js && mv js/browser/bluebird.min.js js/browser/bluebird.core.min.js" + }, + "homepage": "https://github.com/petkaantonov/bluebird", + "repository": { + "type": "git", + "url": "git://github.com/petkaantonov/bluebird.git" + }, + "bugs": { + "url": "http://github.com/petkaantonov/bluebird/issues" + }, + "license": "MIT", + "author": { + "name": "Petka Antonov", + "email": "petka_antonov@hotmail.com", + "url": "http://github.com/petkaantonov/" + }, + "devDependencies": { + "acorn": "^6.0.2", + "acorn-walk": "^6.1.0", + "baconjs": "^0.7.43", + "bluebird": "^2.9.2", + "body-parser": "^1.10.2", + "browserify": "^8.1.1", + "cli-table": "~0.3.1", + "co": "^4.2.0", + "cross-spawn": "^0.2.3", + "glob": "^4.3.2", + "grunt-saucelabs": "~8.4.1", + "highland": "^2.3.0", + "istanbul": "^0.3.5", + "jshint": "^2.6.0", + "jshint-stylish": "~0.2.0", + "kefir": "^2.4.1", + "mkdirp": "~0.5.0", + "mocha": "~2.1", + "open": "~0.0.5", + "optimist": "~0.6.1", + "rimraf": "~2.2.6", + "rx": "^2.3.25", + "serve-static": "^1.7.1", + "sinon": "~1.7.3", + "uglify-js": "~2.4.16" + }, + "readmeFilename": "README.md", + "main": "./js/release/bluebird.js", + "webpack": "./js/release/bluebird.js", + "browser": "./js/browser/bluebird.js", + "files": [ + "js/browser", + "js/release", + "LICENSE" + ] +} diff --git a/test/fixtures/bluebird/test.js b/test/fixtures/bluebird/test.js new file mode 100644 index 00000000000000..b68a3a2ce3d150 --- /dev/null +++ b/test/fixtures/bluebird/test.js @@ -0,0 +1 @@ +require('bluebird') diff --git a/test/parallel/test-require-invalid-main-no-exports.js b/test/parallel/test-require-invalid-main-no-exports.js new file mode 100644 index 00000000000000..676053ce3565c3 --- /dev/null +++ b/test/parallel/test-require-invalid-main-no-exports.js @@ -0,0 +1,20 @@ +'use strict'; + +require('../common'); + +// Test that a nonexistent "main" entry in a package.json that also omits an +// "exports" entry will be ignored if it can be found in node_modules instead +// rather than throwing. +// +// Throwing is perhaps "correct" behavior, but it will break bluebird tests +// as of this writing. + +const assert = require('assert'); +const { spawnSync } = require('child_process'); +const fixtures = require('../common/fixtures'); + +const { error, status, stderr } = + spawnSync(process.execPath, [fixtures.path('bluebird', 'test.js')]); + +assert.ifError(error); +assert.strictEqual(status, 0, stderr);