Debian Codegraph @

packages/babel-preset-env/scripts/smoke-test.js

raw symbols SCIP
1 const fs = require("fs");
2 const execSync = require("child_process").execSync;
3 const path = require("path");
4 const pkg = require("../package.json");
5
6 let errorOccurred = false;
7
8 const tempFolderPath = path.join(__dirname, "../tmp");
9 const packPath = path.join(__dirname, `../babel-preset-env-${pkg.version}.tgz`);
10
11 try {
12 console.log("Creating package");
13 execSync("npm pack");
14
15 console.log("Setting up smoke test dependencies");
16
17 fs.mkdirSync(tempFolderPath);
18 process.chdir(tempFolderPath);
19
20 const babelCliVersion = pkg.devDependencies["babel-cli"];
21
22 if (!babelCliVersion) {
23 throw new Error("Could not read version of babel-cli from package.json");
24 }
25
26 fs.writeFileSync(
27 path.join(tempFolderPath, "package.json"),
28 `
29 {
30 "name": "babel-preset-env-smoke-test",
31 "private": true,
32 "version": "1.0.0",
33 "scripts": {
34 "build": "babel index.js --out-file index.es6"
35 },
36 "dependencies": {
37 "babel-cli": "${babelCliVersion}",
38 "babel-preset-env": "${packPath}"
39 }
40 }
41 `
42 );
43
44 execSync("npm install");
45
46 console.log("Setting up 'usage' smoke test");
47
48 fs.writeFileSync(
49 path.join(tempFolderPath, ".babelrc"),
50 `
51 {
52 "presets": [
53 ["env", {
54 modules: false,
55 useBuiltIns: "usage"
56 }]
57 ]
58 }
59 `
60 );
61
62 fs.writeFileSync(
63 path.join(tempFolderPath, "index.js"),
64 `
65 const foo = new Promise((resolve) => {
66 resolve(new Map());
67 });
68 `
69 );
70
71 console.log("Running 'usage' smoke test");
72
73 execSync("npm run build");
74
75 console.log("Setting up 'entry' smoke test");
76
77 fs.writeFileSync(
78 path.join(tempFolderPath, ".babelrc"),
79 `
80 {
81 "presets": [
82 ["env", {
83 modules: false,
84 useBuiltIns: "entry"
85 }]
86 ]
87 }
88 `
89 );
90
91 fs.writeFileSync(
92 path.join(tempFolderPath, "index.js"),
93 `
94 import "@babel/polyfill";
95 1 ** 2;
96 `
97 );
98
99 console.log("Running 'entry' smoke test");
100
101 execSync("npm run build");
102 } catch (e) {
103 console.log(e);
104 errorOccurred = true;
105 }
106
107 console.log("Cleaning up");
108 fs.removeSync(tempFolderPath);
109 fs.removeSync(packPath);
110
111 process.exitCode = errorOccurred ? 1 : 0;