diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-15 09:23:31 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-15 09:23:31 +0800 |
| commit | be4d8a9462de720e6b22cf291860cf4a87e066ae (patch) | |
| tree | 423bb8ad04d05f3ca47d67141bad6d536f2aef43 /node_modules/babel-plugin-uglify/test | |
| parent | b5134a5a8d953fd741a17536959293ba855ffd66 (diff) | |
updates
Diffstat (limited to 'node_modules/babel-plugin-uglify/test')
| -rw-r--r-- | node_modules/babel-plugin-uglify/test/fixtures/actual.js | 6 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/test/fixtures/expected.js | 7 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/test/index.js | 53 |
3 files changed, 66 insertions, 0 deletions
diff --git a/node_modules/babel-plugin-uglify/test/fixtures/actual.js b/node_modules/babel-plugin-uglify/test/fixtures/actual.js new file mode 100644 index 00000000..6f5503c3 --- /dev/null +++ b/node_modules/babel-plugin-uglify/test/fixtures/actual.js @@ -0,0 +1,6 @@ +export function doSmth(hiThere) {
+ hiThere();
+ if (false) {
+ console.log('dead code');
+ }
+};
diff --git a/node_modules/babel-plugin-uglify/test/fixtures/expected.js b/node_modules/babel-plugin-uglify/test/fixtures/expected.js new file mode 100644 index 00000000..8c8c7a5a --- /dev/null +++ b/node_modules/babel-plugin-uglify/test/fixtures/expected.js @@ -0,0 +1,7 @@ +'use strict'; + +function doSmth(t) { + t(); +} + +exports.__esModule = !0, exports.doSmth = doSmth; diff --git a/node_modules/babel-plugin-uglify/test/index.js b/node_modules/babel-plugin-uglify/test/index.js new file mode 100644 index 00000000..127e3938 --- /dev/null +++ b/node_modules/babel-plugin-uglify/test/index.js @@ -0,0 +1,53 @@ +var assert = require('assert');
+var babel = require('babel');
+var chalk = require('chalk');
+var clear = require('clear');
+var diff = require('diff');
+var fs = require('fs');
+
+require('babel/register')(JSON.parse(fs.readFileSync(__dirname + '/../.babelrc')));
+
+var pluginPath = require.resolve('../src');
+
+function runTest() {
+ var output = babel.transformFileSync(__dirname + '/fixtures/actual.js', {
+ optional: ['runtime'],
+ plugins: [pluginPath + ':after'],
+ filenameRelative: 'test/fixtures/actual.js'
+ });
+
+ var expected = fs.readFileSync(__dirname + '/fixtures/expected.js', 'utf-8');
+
+ function normalizeLines(str) {
+ return str.trimRight().replace(/\r\n/g, '\n');
+ }
+
+ diff.diffLines(normalizeLines(output.code), normalizeLines(expected))
+ .forEach(function (part) {
+ var value = part.value;
+ if (part.added) {
+ value = chalk.green(part.value);
+ } else if (part.removed) {
+ value = chalk.red(part.value);
+ }
+ process.stdout.write(value);
+ });
+
+ console.log();
+}
+
+if (process.argv.indexOf('--watch') >= 0) {
+ require('watch').watchTree(__dirname + '/..', function () {
+ delete require.cache[pluginPath];
+ clear();
+ console.log('Press Ctrl+C to stop watching...');
+ console.log('================================');
+ try {
+ runTest();
+ } catch (e) {
+ console.error(chalk.magenta(e.stack));
+ }
+ });
+} else {
+ runTest();
+}
|
