Skip to content

Commit

Permalink
Add js_engine input test (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizarmah committed Mar 19, 2024
1 parent 43cd120 commit 6023eb0
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/js_engine/babel/main.expected.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions tests/js_engine/main.js
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/js_engine/uglify-js/main.expected.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6023eb0

Please sign in to comment.