Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add js_engine input test #38

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good enough for now.

We can build it as we go.
Whenever a user opens an issue with some specific example, we can add the lines here to test for it.

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.