Commit 3688634
Changed files (8)
test
fixtures
js-project
ts-project
test/fixtures/js-project/package.json
@@ -0,0 +1,7 @@
+{
+ "private": true,
+ "type": "module",
+ "dependencies": {
+ "zx": "*"
+ }
+}
test/fixtures/js-project/script.js
@@ -0,0 +1,15 @@
+// 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.
+
+$`echo js-script`
test/fixtures/ts-project/package.json
@@ -0,0 +1,8 @@
+{
+ "private": true,
+ "type": "module",
+ "dependencies": {
+ "typescript": "^4.7.3",
+ "zx": "*"
+ }
+}
test/fixtures/ts-project/script.ts
@@ -0,0 +1,18 @@
+// 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 { $, ProcessPromise } from 'zx'
+
+let p: ProcessPromise = $`echo ts-script`
+await p
test/fixtures/ts-project/tsconfig.json
@@ -0,0 +1,11 @@
+{
+ "compilerOptions": {
+ "outDir": "./build",
+ "target": "es2021",
+ "module": "esnext",
+ "moduleResolution": "node16",
+ "allowSyntheticDefaultImports": true,
+ "strict": true
+ },
+ "include": ["*.ts"]
+}
test/package.test.js
@@ -18,40 +18,36 @@ import '../build/globals.js'
const test = suite('package')
-test.before(async () => {
+test.before.each(async () => {
$.verbose = false
const pack = await $`npm pack`
await $`tar xf ${pack}`
await $`rm ${pack}`.nothrow()
- const fullPath = path.resolve('package')
- await $`mkdir -p /tmp/zx-pack-test`
- fs.writeFileSync(
- '/tmp/zx-pack-test/package.json',
- JSON.stringify({ private: true, dependencies: { zx: '*' } })
- )
- cd('/tmp/zx-pack-test')
- await $`npm i`
- await $`rm -rf /tmp/zx-pack-test/node_modules/zx`
- await $`mv ${fullPath} /tmp/zx-pack-test/node_modules/zx`
})
-test.after(async () => {
- await $`rm -rf /tmp/zx-pack-test`.nothrow()
+test('ts project', async () => {
+ const pack = path.resolve('package')
+ const out = await within(async () => {
+ cd('test/fixtures/ts-project')
+ await $`npm i`
+ await $`rm -rf node_modules/zx`
+ await $`mv ${pack} node_modules/zx`
+ await $`npx tsc`
+ return $`node build/script.js`
+ })
+ assert.match(out.stderr, 'ts-script')
})
-test('zx globals works', async () => {
- fs.writeFileSync('/tmp/zx-pack-test/script.mjs', 'await $`echo hello`')
- let out = await $`npx zx script.mjs`
- assert.match(out.toString(), 'hello')
-})
-
-test('imports works', async () => {
- fs.writeFileSync(
- '/tmp/zx-pack-test/script.mjs',
- 'import {$} from "zx"; await $`printf imported`'
- )
- let out = await $`node script.mjs`
- assert.match(out.toString(), 'imported')
+test('js project with zx', async () => {
+ const pack = path.resolve('package')
+ const out = await within(async () => {
+ cd('test/fixtures/js-project')
+ await $`rm -rf node_modules`
+ await $`mkdir node_modules`
+ await $`mv ${pack} node_modules/zx`
+ return $`npx zx script.js`
+ })
+ assert.match(out.stderr, 'js-script')
})
test.run()
.gitignore
@@ -1,5 +1,6 @@
-/node_modules/
-/build/
-/coverage/
+node_modules/
+build/
+coverage/
+package/
package-lock.json
yarn.lock
.prettierignore
@@ -1,6 +1,7 @@
-/node_modules/
-/build/
-/coverage/
+node_modules/
+build/
+coverage/
+package/
package-lock.json
yarn.lock
*.md