RequireJS demo automation

This commit is contained in:
SheetJS 2024-04-28 00:43:55 -04:00
parent b503ebc14d
commit 954ab5fe7e
5 changed files with 169 additions and 11 deletions

View File

@ -41,9 +41,9 @@ This demo was tested in the following environments:
| ViteJS | Date |
|:---------|:-----------|
| `5.2.8` | 2024-04-13 |
| `4.5.3` | 2024-04-13 |
| `3.2.10` | 2024-04-13 |
| `5.2.10` | 2024-04-27 |
| `4.5.3` | 2024-04-27 |
| `3.2.10` | 2024-04-27 |
:::

View File

@ -40,8 +40,8 @@ This demo was tested in the following environments:
| RequireJS | Date |
|:----------|:-----------|
| `2.3.6` | 2024-03-01 |
| `2.1.22` | 2023-12-04 |
| `2.3.6` | 2024-04-27 |
| `2.1.22` | 2024-04-27 |
:::

View File

@ -35,7 +35,7 @@ This demo was tested in the following environments:
| Version | Date |
|:----------|:-----------|
| `1.2.246` | 2023-12-04 |
| `1.2.246` | 2024-04-27 |
:::
@ -65,7 +65,7 @@ import { utils, writeFile } from 'xlsx';
:::danger pass
When this demo was tested against the `@swc/core@1.3.100`, `spack` crashed:
When this demo was tested against recent versions of `@swc/core`, `spack` crashed:
```
thread '<unnamed>' panicked at 'cannot access a scoped thread local variable without calling `set` first',
@ -73,6 +73,8 @@ thread '<unnamed>' panicked at 'cannot access a scoped thread local variable wit
**This is a bug in SWC**
This bug is known to affect versions `1.3.100` and `1.4.17`.
Until the bug is fixed, it is strongly recommended to use `@swc/core@1.2.246`.
:::

View File

@ -50,10 +50,10 @@ npx astro telemetry disable
This demo was tested in the following environments:
| AstroJS | Template | Date |
|:--------|:------------------|:-----------|
| `3.6.5` |: Starlight 0.14.0 | 2024-04-14 |
| `4.6.1` |: Starlight 0.21.5 | 2024-04-14 |
| AstroJS | Template | Date |
|:--------|:-----------------|:-----------|
| `3.6.5` | Starlight 0.14.0 | 2024-04-14 |
| `4.6.1` | Starlight 0.21.5 | 2024-04-14 |
:::

156
tests/bundler-requirejs.sh Executable file
View File

@ -0,0 +1,156 @@
#!/bin/bash
# https://docs.sheetjs.com/docs/demos/frontend/bundler/requirejs
# requires global puppeteer and express
# sudo npm i -g puppeteer express@4
cd /tmp
rm -rf sheetjs-requirejs
mkdir sheetjs-requirejs
cd sheetjs-requirejs
curl -LO https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/xlsx.full.min.js
cat >SheetJSRequire.js <<EOF
require(["xlsx"], function(XLSX) {
document.getElementById("xport").addEventListener("click", function() {
/* fetch JSON data and parse */
var url = "https://docs.sheetjs.com/executive.json";
fetch(url).then(function(res) { return res.json(); }).then(function(raw_data) {
/* filter for the Presidents */
var prez = raw_data.filter(function(row) { return row.terms.some(function(term) { return term.type === "prez"; }); });
/* sort by first presidential term */
prez.forEach(function(row) { row.start = row.terms.find(function(term) {return term.type === "prez"; }).start; });
prez.sort(function(l,r) { return l.start.localeCompare(r.start); });
/* flatten objects */
var rows = prez.map(function(row) { return {
name: row.name.first + " " + row.name.last,
birthday: row.bio.birthday
}; });
/* generate worksheet and workbook */
var worksheet = XLSX.utils.json_to_sheet(rows);
var workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, "Dates");
/* fix headers */
XLSX.utils.sheet_add_aoa(worksheet, [["Name", "Birthday"]], { origin: "A1" });
/* calculate column width */
var max_width = rows.reduce(function(w, r) { return Math.max(w, r.name.length); }, 10);
worksheet["!cols"] = [ { wch: max_width } ];
/* create an XLSX file and try to save to Presidents.xlsx */
//XLSX.writeFileXLSX(workbook, "Presidents.xlsx");
console.log(XLSX.utils.sheet_to_csv(worksheet));
});
});
});
EOF
cat >build.js <<EOF
({
baseUrl: ".",
name: "SheetJSRequire",
paths: {
xlsx: "./xlsx.full.min"
},
out: "SheetJSRequire.min.js"
});
EOF
cat >test1.js <<EOF
const puppeteer = require('puppeteer');
const express = require('express');
const app = express();
app.use(express.static('./'));
app.listen(7262, async() => {
await new Promise((res,rej) => setTimeout(res, 1000));
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.on("console", msg => console.log("PAGE LOG:", msg.text()));
await page.setViewport({width: 1920, height: 1080});
await page.goto('http://localhost:7262/', {waitUntil: 'domcontentloaded'});
/* wait for requirejs to request xlsx.full.min.js */
await page.waitForRequest(request => request.url().indexOf('xlsx.full.min.js') !== -1);
await new Promise((res,rej) => setTimeout(res, 1000));
await page.click("#xport");
await new Promise((res,rej) => setTimeout(res, 1000));
await browser.close();
process.exit();
});
EOF
cat >test2.js <<EOF
const puppeteer = require('puppeteer');
const express = require('express');
const app = express();
app.use(express.static('./'));
app.listen(7262, async() => {
await new Promise((res,rej) => setTimeout(res, 1000));
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.on("console", msg => console.log("PAGE LOG:", msg.text()));
await page.setViewport({width: 1920, height: 1080});
await page.goto('http://localhost:7262/optimized.html');
await page.click("#xport");
await new Promise((res,rej) => setTimeout(res, 1000));
await browser.close();
process.exit();
});
EOF
for n in 2.3.6 2.1.22; do
echo $n Standalone
cat >index.html <<EOF
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<h1>SheetJS Presidents Demo</h1>
<button id="xport">Click here to export</button>
<script src="http://requirejs.org/docs/release/$n/comments/require.js"></script>
<script>
/* Wire up RequireJS */
require.config({
baseUrl: ".",
name: "SheetJSRequire",
paths: {
xlsx: "./xlsx.full.min"
}
});
</script>
<script src="SheetJSRequire.js"></script>
</body>
</html>
EOF
node test1.js
echo $n Optimizer
npx -p requirejs@$n r.js -o build.js
cat >optimized.html <<EOF
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<h1>SheetJS Presidents Demo</h1>
<button id="xport">Click here to export</button>
<script src="http://requirejs.org/docs/release/$n/comments/require.js"></script>
<script src="SheetJSRequire.min.js"></script>
</body>
</html>
EOF
node test2.js
done