From 4a06396593da9142a498525a8aaec028dde2457a Mon Sep 17 00:00:00 2001 From: Brian Mulhall Date: Mon, 13 Apr 2020 18:46:03 -0500 Subject: [PATCH] updated the test cases to handle the empty string, valid JS, invalid JS cases and then a case to check the error object has the fields we need and one to keep tabs on the numeric separator support I requested (I'll remove it when it fails) --- packages/minifier-js/minifier-tests.js | 37 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/packages/minifier-js/minifier-tests.js b/packages/minifier-js/minifier-tests.js index c49d8b64a4..49d11900b8 100644 --- a/packages/minifier-js/minifier-tests.js +++ b/packages/minifier-js/minifier-tests.js @@ -1,6 +1,31 @@ -Tinytest.add('minifier-js - verify terser is able to minify files', (test) => { - let terserResult = meteorJsMinify('function add(first,second){return first + second; }\n'); - test.equal(terserResult.code, 'function add(n,d){return n+d}'); +Tinytest.add('minifier-js - verify how terser handles an empty string', (test) => { + let result = meteorJsMinify(''); + test.equal(result.code, ''); + test.equal(result.minifier, 'terser'); +}); + +Tinytest.add('minifier-js - verify terser is able to minify valid javascript', (test) => { + let result = meteorJsMinify('function add(first,second){return first + second; }\n'); + test.equal(result.code, 'function add(n,d){return n+d}'); + test.equal(result.minifier, 'terser'); +}); + +Tinytest.add('minifier-js - verify error handling is done as expected', (test) => { + test.throws( () => meteorJsMinify('let name = {;\n'), undefined ); +}); + +Tinytest.add('minifier-js - verify tersers error object has the fields we use for reporting errors to users', (test) => { + let result; + try { + result = meteorJsMinify('let name = {;\n'); + } + catch (err) { + test.isNotUndefined(err.name); + test.isNotUndefined(err.message); + test.isNotUndefined(err.filename); + test.isNotUndefined(err.line); + test.isNotUndefined(err.col); + } }); // this feature has been reqested in this issue https://github.com/terser/terser/issues/632 @@ -8,8 +33,4 @@ Tinytest.add('minifier-js - verify terser is able to minify files', (test) => { // its been done and can remove this test :) Tinytest.add('minifier-js - unsupported feature test (numeric seperators)', (test) => { test.throws(() => meteorJsMinify('let number = 1_000_000_000_000;\n') ); -}); - -Tinytest.add('minifier-js - verify error handling is done correctly', (test) => { - test.throws(() => meteorJsMinify('let name = {;\n')); -}); +}); \ No newline at end of file