#!/bin/sh
set -e
DIR=$(mktemp -d)
trap "rm -rf $DIR" EXIT
cd "$DIR"
pkgjs-ln form-data
pkgjs-ln follow-redirects
pkgjs-ln proxy-from-env
pkgjs-ln axios

node -e '
const assert = require("assert");
const axios = require("axios");

(async () => {
  const res = await axios.get("https://www.debian.org/");
  assert.strictEqual(res.status, 200, "GET https://www.debian.org/ should return status 200");
  assert.ok(typeof res.data === "string" && res.data.length > 0, "response body should be a non-empty string");
  assert.ok(res.headers, "response headers should be set");
  console.log("CJS network test passed (GET https://www.debian.org/)");
})().catch((err) => {
  console.error(err);
  process.exit(1);
});
'

node --input-type=module -e '
import assert from "assert";
import axios from "axios";

const res = await axios.get("https://www.debian.org/");
assert.strictEqual(res.status, 200, "GET https://www.debian.org/ should return status 200");
assert.ok(typeof res.data === "string" && res.data.length > 0, "response body should be a non-empty string");
console.log("ESM network test passed (GET https://www.debian.org/)");
'
