Commit 2064eb9

Anton Medvedev <anton@medv.io>
2022-06-03 23:08:13
Add package.test.js
1 parent 4944122
Changed files (2)
test/index.test.js
@@ -112,8 +112,6 @@ test('pipes are working', async () => {
 })
 
 test('question() works', async () => {
-  let log = console.log
-  console.log = () => {}
   let p = question('foo or bar? ', { choices: ['foo', 'bar'] })
   setImmediate(() => {
     process.stdin.emit('data', 'fo')
@@ -121,12 +119,9 @@ test('question() works', async () => {
     process.stdin.emit('data', '\n')
   })
   assert.is(await p, 'foo')
-  console.log = log
 })
 
 test('empty question() works', async () => {
-  let log = console.log
-  console.log = () => {}
   let p = question(undefined, { choices: [] })
   setImmediate(() => {
     process.stdin.emit('data', 'xxx')
@@ -134,7 +129,6 @@ test('empty question() works', async () => {
     process.stdin.emit('data', '\n')
   })
   assert.match(await p, 'xxx')
-  console.log = log
 })
 
 test('ProcessPromise', async () => {
test/package.test.js
@@ -0,0 +1,40 @@
+// Copyright 2022 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import { test } from 'uvu'
+import * as assert from 'uvu/assert'
+import '../build/globals.js'
+
+$.verbose = false
+
+test('package works', async () => {
+  let pack
+  try {
+    await $`mkdir -p /tmp/zx-pack-test/node_modules`
+    pack = await $`npm pack`
+    await $`tar xf ${pack}`
+    await $`rm ${pack}`.nothrow()
+    await $`mv package/ /tmp/zx-pack-test/node_modules/zx`
+    let packageJSON = {private: true, dependencies: {zx: '*'}}
+    fs.writeFileSync('/tmp/zx-pack-test/package.json', JSON.stringify(packageJSON))
+    fs.writeFileSync('/tmp/zx-pack-test/script.mjs', 'await $`echo hello`')
+    cd('/tmp/zx-pack-test')
+    let out = await $`npx zx script.mjs`
+    assert.match(out.toString(), 'hello')
+  } finally {
+    await $`rm -rf /tmp/zx-pack-test`.nothrow()
+  }
+})
+
+test.run()