UNPKG

1.41 kBJavaScriptView Raw
1/*
2Copyright 2019 Adobe. All rights reserved.
3This file is licensed to you under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License. You may obtain a copy
5of the License at http://www.apache.org/licenses/LICENSE-2.0
6Unless required by applicable law or agreed to in writing, software distributed under
7the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8OF ANY KIND, either express or implied. See the License for the specific language
9governing permissions and limitations under the License.
10*/
11
12const path = require('path')
13const { stdout, stderr } = require('stdout-stderr')
14
15process.on('unhandledRejection', error => {
16 throw error
17})
18
19// trap console log
20beforeEach(() => { stdout.start(); stderr.start(); stdout.print = true })
21afterEach(() => { stdout.stop(); stderr.stop() })
22
23// quick normalization to test windows/unix paths
24global.n = p => path.normalize(p)
25global.r = p => path.resolve(p)
26
27global.assertDependencies = (fs, dependencies, devDependencies) => {
28 expect(JSON.parse(fs.readFileSync('package.json').toString())).toEqual(expect.objectContaining({
29 dependencies,
30 devDependencies
31 }))
32}
33
34global.assertNodeEngines = (fs, nodeEngines) => {
35 expect(JSON.parse(fs.readFileSync('package.json').toString())).toEqual(expect.objectContaining({
36 engines: { node: nodeEngines }
37 }))
38}