|
| 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 assert from 'node:assert' |
| 16 | +import { tempdir, $, path, fs } from '../../build/index.js' |
| 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('package.json artifact', () => { |
| 23 | + let tmp |
| 24 | + let t$ |
| 25 | + |
| 26 | + before(async () => { |
| 27 | + tmp = tempdir() |
| 28 | + t$ = $({ cwd: tmp, quiet: true }) |
| 29 | + |
| 30 | + await fs.copy( |
| 31 | + path.resolve(root, 'package.json'), |
| 32 | + path.resolve(tmp, 'package.json') |
| 33 | + ) |
| 34 | + await fs.copy( |
| 35 | + path.resolve(root, 'scripts/clean-package-json.mjs'), |
| 36 | + path.resolve(tmp, 'scripts/clean-package-json.mjs') |
| 37 | + ) |
| 38 | + }) |
| 39 | + |
| 40 | + after(() => fs.remove(tmp)) |
| 41 | + |
| 42 | + it('handle exist properties required for publishing', async () => { |
| 43 | + await t$`node scripts/clean-package-json.mjs` |
| 44 | + // to throw if manifest is not correct |
| 45 | + const pkgJson = JSON.parse( |
| 46 | + fs.readFileSync(path.resolve(tmp, 'package.json')) |
| 47 | + ) |
| 48 | + |
| 49 | + assert.equal(pkgJson.name, 'zx') |
| 50 | + assert.equal(pkgJson.description, 'A tool for writing better scripts') |
| 51 | + assert.equal(pkgJson.prettier, undefined) |
| 52 | + assert.equal(pkgJson.scripts, undefined) |
| 53 | + }) |
| 54 | +}) |
0 commit comments