Skip to content

Commit 5511032

Browse files
add sources for the cloudflare speedtest
1 parent e6516c2 commit 5511032

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed

tasks/measurements/cloudflare/__init__.py

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Cloudflare speedtest netunicorn task sources
2+
3+
This folder contains source code for Cloudflare speedtest adapted as netunicorn task.
4+
5+
In particular, to run the speedtest, you need to bundle the cloudflare speedtest npm module with the index.js file that uses these code. When the HTML page inporting this bundle would be opened, the speedtest would be run and results would be assigned to the window variable testResults, and window.testFinished would be set to true.
6+
7+
Currently, the task refers to the bundled version of the speedtest module, which is located in the `dist` folder. To rebuild the bundle, run `npm run build` in the `tasks/measurements/cloudflare` folder.
8+
9+
The bundled version is published as "cloudflare-speedtest-bundle:0.1" release in the netunicorn-repo.
10+
11+
## How to bundle the speedtest module
12+
13+
If you want to change index.js, you'll need to create the new bundle. For this:
14+
1. Install npm
15+
2. Create a new npm project in the `tasks/measurements/cloudflare/src` folder: `npm init`
16+
3. Install the required modules: `npm install @cloudflare/speedtest babel-loader webpack webpack-cli`
17+
4. Modify `index.js` as needed.
18+
5. Run `npx webpack` to create the bundle in the folder specified in the `webpack.config.js` file.
19+
6. Publish your bundle somewhere and change the requirements of the corresponding netunicorn task to point to your new bundle.
20+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import SpeedTest from '@cloudflare/speedtest';
2+
3+
window.testFinished = false;
4+
const test = new SpeedTest();
5+
test.onFinish = results => {
6+
window.testResults = results;
7+
window.testFinished = true;
8+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "temp",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"webpack": "^5.89.0",
14+
"webpack-cli": "^5.1.4"
15+
},
16+
"dependencies": {
17+
"@cloudflare/speedtest": "^1.3.0",
18+
"babel-loader": "^9.1.3"
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<script src="/tmp/cloudflare/speedtest/bundle.js"></script>
7+
<title>CloudFlare SpeedTest</title>
8+
</head>
9+
10+
<body>
11+
</body>
12+
13+
</html>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
entry: './index.js',
3+
output: {
4+
filename: 'bundle.js',
5+
path: "/tmp/cloudflare/speedtest/",
6+
},
7+
module: {
8+
rules: [
9+
{
10+
test: /\.js$/,
11+
exclude: /node_modules/,
12+
use: {
13+
loader: 'babel-loader',
14+
},
15+
},
16+
],
17+
},
18+
};

0 commit comments

Comments
 (0)