Skip to content

Commit

Permalink
e2e: esm test
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Mar 23, 2024
1 parent 8da36a5 commit 077d466
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
11 changes: 10 additions & 1 deletion test/e2e.sh
Expand Up @@ -96,8 +96,17 @@ echo Test: cjs
cd $temp_dir/e2e/cjs

echo Installing
echo "{}" >package.json
npm i npm-check-updates@latest --registry $registry_local

echo Running test
REGISTRY=$registry_local node $temp_dir/e2e/cjs/index.js

# Test: esm
echo Test: esm
cd $temp_dir/e2e/esm

echo Installing
npm i npm-check-updates@latest --registry $registry_local

echo Running test
REGISTRY=$registry_local node $temp_dir/e2e/esm/index.js
1 change: 0 additions & 1 deletion test/e2e/cjs/index.js
@@ -1,5 +1,4 @@
/** NOTE: This script is copied into a temp directory by the e2e test and dependencies are installed from the local verdaccio registry. */

const ncu = require('npm-check-updates')
const assert = require('assert')

Expand Down
1 change: 1 addition & 0 deletions test/e2e/cjs/package.json
@@ -0,0 +1 @@
{}
28 changes: 28 additions & 0 deletions test/e2e/esm/index.js
@@ -0,0 +1,28 @@
/** NOTE: This script is copied into a temp directory by the e2e test and dependencies are installed from the local verdaccio registry. */
import assert from 'assert'
import ncu from 'npm-check-updates'

const registry = process.env.REGISTRY || 'http://localhost:4873'

// must exit with error code on unhandledRejection, otherwise script will exit with 0 if an assertion fails in the async block
process.on('unhandledRejection', (reason, p) => {
process.exit(1)
})

// test
;(async () => {
const upgraded = await ncu.run({
// --pre 1 to ensure that an upgrade is always suggested even if npm-check-updates is on a prerelease version
pre: true,
packageData: JSON.stringify({
dependencies: {
'npm-check-updates': '1.0.0',
},
}),
registry,
})

console.info(upgraded)

assert.notStrictEqual(upgraded['npm-check-updates'], '1.0.0', 'npm-check-updates should be upgraded')
})()
3 changes: 3 additions & 0 deletions test/e2e/esm/package.json
@@ -0,0 +1,3 @@
{
"type": "module"
}

0 comments on commit 077d466

Please sign in to comment.