diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78b9420..8df1167 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -94,3 +94,45 @@ jobs: git diff --exit-code --no-index \ tests/output/main.expected.js \ tests/output/prod/js/main.min.js + + js_engine_babel: + name: "js_engine / babel" + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Test js_engine babel + uses: ./ + with: + directory: "tests/js_engine" + output: "tests/js_engine/babel" + js_engine: "babel" + + - name: Assert js_engine babel result matches expected + run: | + git diff --exit-code --no-index \ + tests/js_engine/babel/main.expected.js \ + tests/js_engine/babel/main.min.js + + js_engine_uglify_js: + name: "js_engine / uglify-js" + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Test js_engine uglify-js + uses: ./ + with: + directory: "tests/js_engine" + output: "tests/js_engine/uglify-js" + js_engine: "uglify-js" + + - name: Assert js_engine uglify-js result matches expected + run: | + git diff --exit-code --no-index \ + tests/js_engine/uglify-js/main.expected.js \ + tests/js_engine/uglify-js/main.min.js diff --git a/tests/js_engine/babel/main.expected.js b/tests/js_engine/babel/main.expected.js new file mode 100644 index 0000000..11d0ca3 --- /dev/null +++ b/tests/js_engine/babel/main.expected.js @@ -0,0 +1 @@ +function addNumbers(c,a){return c+a}function subtractNumbers(c,a){return c-a}const name="GitHub Actions";console.log(`Testing minification with ${"GitHub Actions"}!`);const numbers=[1,2,3,4,5],doubledNumbers=numbers.map(a=>2*a);console.log(doubledNumbers);const calculator={add:(a,b)=>a+b,subtract:(a,b)=>a-b,multiply:(a,b)=>a*b,divide:(a,b)=>a/b};console.log(calculator.add(5,7)),console.log(calculator.subtract(10,5));async function fetchData(a){try{const b=await fetch(a),c=await b.json();console.log(c)}catch(a){console.error("Error fetching data:",a)}}fetchData("https://api.github.com/repos/nizarmah/auto-minify"); \ No newline at end of file diff --git a/tests/js_engine/main.js b/tests/js_engine/main.js new file mode 100644 index 0000000..d57f091 --- /dev/null +++ b/tests/js_engine/main.js @@ -0,0 +1,50 @@ +// Example JavaScript file for minification testing + +// Function to add two numbers +function addNumbers(a, b) { + return a + b; +} + +// Function to subtract two numbers +function subtractNumbers(a, b) { + return a - b; +} + +// Using a template string and a variable +const name = "GitHub Actions"; +console.log(`Testing minification with ${name}!`); + +// An array of numbers +const numbers = [1, 2, 3, 4, 5]; + +// Using map to create a new array +const doubledNumbers = numbers.map((number) => number * 2); +console.log(doubledNumbers); + +// Object with methods +const calculator = { + add: (x, y) => x + y, + subtract: (x, y) => x - y, + multiply: (x, y) => x * y, + divide: (x, y) => x / y, +}; + +// Using the calculator object +console.log(calculator.add(5, 7)); +console.log(calculator.subtract(10, 5)); + +// Testing async function +async function fetchData(url) { + try { + const response = await fetch(url); + const data = await response.json(); + console.log(data); + } catch (error) { + console.error("Error fetching data:", error); + } +} + +// Invoking async function (this will fail without a valid URL or in a non-browser environment) +fetchData("https://api.github.com/repos/nizarmah/auto-minify"); + +// End of file diff --git a/tests/js_engine/uglify-js/main.expected.js b/tests/js_engine/uglify-js/main.expected.js new file mode 100644 index 0000000..d279ced --- /dev/null +++ b/tests/js_engine/uglify-js/main.expected.js @@ -0,0 +1 @@ +function addNumbers(t,o){return t+o}function subtractNumbers(t,o){return t-o}const name="GitHub Actions",numbers=(console.log(`Testing minification with ${name}!`),[1,2,3,4,5]),doubledNumbers=numbers.map(t=>2*t),calculator=(console.log(doubledNumbers),{add:(t,o)=>t+o,subtract:(t,o)=>t-o,multiply:(t,o)=>t*o,divide:(t,o)=>t/o});async function fetchData(t){try{var o=await(await fetch(t)).json();console.log(o)}catch(t){console.error("Error fetching data:",t)}}console.log(calculator.add(5,7)),console.log(calculator.subtract(10,5)),fetchData("https://api.github.com/repos/nizarmah/auto-minify"); \ No newline at end of file