|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import { tempdir, $, path, fs } from '../../build/index.js' |
| 16 | +import assert from 'node:assert' |
| 17 | +import { describe, before, after, it } from 'node:test' |
| 18 | + |
| 19 | +const __dirname = path.dirname(new URL(import.meta.url).pathname) |
| 20 | +const root = path.resolve(__dirname, '../../') |
| 21 | + |
| 22 | +describe('npm artifact', () => { |
| 23 | + let tmp |
| 24 | + let zxdir |
| 25 | + let t$ |
| 26 | + |
| 27 | + const pkgJson = { |
| 28 | + name: 'zx-test', |
| 29 | + dependencies: { |
| 30 | + typescript: '^5', |
| 31 | + '@types/node': '*', |
| 32 | + '@types/fs-extra': '*' |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + before(async () => { |
| 37 | + tmp = tempdir() |
| 38 | + t$ = $({cwd: tmp, quiet: true}) |
| 39 | + zxdir = path.resolve(tmp, 'node_modules/zx') |
| 40 | + |
| 41 | + await fs.outputJSON(path.resolve(tmp, 'package.json'), pkgJson) |
| 42 | + await t$`npm i` |
| 43 | + // `file:<path>` dep mounts `node_modules` too, so we use cloning here |
| 44 | + await fs.copy(path.resolve(root, 'package.json'), path.resolve(zxdir, 'package.json')) |
| 45 | + await fs.copy(path.resolve(root, 'build'), path.resolve(zxdir, 'build')) |
| 46 | + }) |
| 47 | + |
| 48 | + after(() => fs.remove(tmp)) |
| 49 | + |
| 50 | + it('looks buildable with tsc', async () => { |
| 51 | + const indexTs = `import {$} from 'zx' |
| 52 | +(async () => { |
| 53 | + await $({verbose: true, stdio: 'pipe'})\`echo hello\` |
| 54 | +})() |
| 55 | +` |
| 56 | + const tsconfig = { |
| 57 | + compilerOptions: { |
| 58 | + module: 'commonjs', |
| 59 | + target: 'esnext', |
| 60 | + outDir: 'build-tsc', |
| 61 | + rootDir: 'src', |
| 62 | + declaration: true, |
| 63 | + declarationMap: false, |
| 64 | + esModuleInterop: true, |
| 65 | + }, |
| 66 | + include: ['src'], |
| 67 | + } |
| 68 | + |
| 69 | + await fs.outputJSON(path.resolve(tmp, 'tsconfig.json'), tsconfig) |
| 70 | + await fs.outputFile(path.resolve(tmp, 'src/index.ts'), indexTs) |
| 71 | + await t$`tsc` |
| 72 | + const result = await t$`node build-tsc/index.js`.text() |
| 73 | + |
| 74 | + assert.strictEqual(result, '$ echo hello\nhello\n') |
| 75 | + }) |
| 76 | +}) |
0 commit comments