diff --git a/.eslintrc.json b/.eslintrc.json
deleted file mode 100644
index 839784c..0000000
--- a/.eslintrc.json
+++ /dev/null
@@ -1,30 +0,0 @@
-{
- "env": { "browser": true },
- "extends": "eslint:recommended",
- "parserOptions": { "ecmaVersion": 6, "sourceType": "module" },
- "rules": {
- "block-scoped-var": "error",
- "consistent-return": "error",
- "eqeqeq": "error",
- "guard-for-in": "error",
- "no-bitwise": "error",
- "no-caller": "error",
- "no-constant-condition": ["error", { "checkLoops": false }],
- "no-extra-parens": "off",
- "no-extend-native": "error",
- "no-loop-func": "error",
- "no-new": "error",
- "no-param-reassign": "error",
- "no-return-assign": "error",
- "no-sequences": "error",
- "no-unused-expressions": "error",
- "no-use-before-define": "error",
- "no-undef": "error",
- "no-eq-null": "error",
- "radix": ["error", "always"],
- "indent": ["error", 2, { "SwitchCase": 0 }],
- "quotes": ["error", "double"],
- "semi": ["error", "always"],
- "strict": ["error", "global"]
- }
-}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 67c1809..670dab4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -9,31 +9,29 @@ on:
jobs:
build:
runs-on: ubuntu-latest
-
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
- - name: Set up PureScript toolchain
+ - name: Set up a PureScript toolchain
uses: purescript-contrib/setup-purescript@main
with:
- purescript: "unstable"
+ purescript: "latest"
purs-tidy: "latest"
+ spago: "unstable"
- name: Cache PureScript dependencies
- uses: actions/cache@v2
+ uses: actions/cache@v4
with:
- key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
+ key: ${{ runner.os }}-spago-${{ hashFiles('**/spago.lock') }}
path: |
.spago
output
- name: Set up Node toolchain
- uses: actions/setup-node@v2
- with:
- node-version: "12.x"
+ uses: actions/setup-node@v4
- name: Cache NPM dependencies
- uses: actions/cache@v2
+ uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
@@ -44,25 +42,20 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-
+ - uses: browser-actions/setup-chrome@v1
+ id: setup-chrome
+
- name: Install NPM dependencies
run: npm install
- - name: Build the project
- run: npm run build
+ - name: Build source
+ run: spago build --censor-stats --strict --ensure-ranges --pedantic-packages
- name: Run tests
- run: npm run test
-
- - name: Check formatting
run: |
- npx eslint src
- purs-tidy check src
+ ${{ steps.setup-chrome.outputs.chrome-path }} --version
+ npm run build
+ npx mocha-headless-chrome --file dist/index.html --args disable-web-security --args no-sandbox --timeout 9999999 --executablePath ${{ steps.setup-chrome.outputs.chrome-path }}
- - name: Verify Bower & Pulp
- run: |
- npm install bower pulp@16.0.0-0
- npx bower install
- npx pulp build -- --censor-lib --strict
- if [ -d "test" ]; then
- npx pulp test
- fi
+ - name: Verify formatting
+ run: purs-tidy check src test
diff --git a/.gitignore b/.gitignore
index 55e7dd6..a40ca34 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@ bower_components
node_modules
package-lock.json
*.lock
+dist/*
diff --git a/bower.json b/bower.json
deleted file mode 100644
index 2e558af..0000000
--- a/bower.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "name": "purescript-affjax-web",
- "homepage": "https://github.com/purescript-contrib/purescript-affjax-web",
- "description": "An asynchronous AJAX library built using Aff that runs on the browser.",
- "keywords": [
- "purescript",
- "ajax"
- ],
- "license": "Apache-2.0",
- "repository": {
- "type": "git",
- "url": "https://github.com/purescript-contrib/purescript-affjax-web.git"
- },
- "ignore": [
- "**/.*",
- "bower_components",
- "node_modules",
- "output",
- "test",
- "tmp",
- "bower.json",
- "gulpfile.js",
- "package.json"
- ],
- "dependencies": {
- "purescript-affjax": "^13.0.0"
- },
- "devDependencies": {
- "purescript-psci-support": "^6.0.0"
- }
-}
diff --git a/browser/index.html b/browser/index.html
new file mode 100644
index 0000000..0d5af84
--- /dev/null
+++ b/browser/index.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ Mocha Tests
+
+
+
+
+
+
+
+
+
+
diff --git a/browser/index.js b/browser/index.js
new file mode 100644
index 0000000..90f2752
--- /dev/null
+++ b/browser/index.js
@@ -0,0 +1,14 @@
+/* global mocha, describe, it */
+//
+// cannot import commonjs, added
+//
+//
+// import mocha from "mocha"
+// import mocha from "mocha/browser-entry.js"
+// import "mocha"
+
+import { main } from 'PureScript/Test.Main/index.js'
+
+mocha.setup("bdd");
+main();
+mocha.run();
diff --git a/eslint.config.mjs b/eslint.config.mjs
new file mode 100644
index 0000000..2edbef8
--- /dev/null
+++ b/eslint.config.mjs
@@ -0,0 +1,8 @@
+import globals from "globals";
+import pluginJs from "@eslint/js";
+
+
+export default [
+ {languageOptions: { globals: globals.browser }},
+ pluginJs.configs.recommended,
+];
\ No newline at end of file
diff --git a/package.json b/package.json
index 8ae99e2..dae3c2a 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,25 @@
{
"private": true,
+ "browserslist": "defaults, not ie <= 11",
"scripts": {
- "build": "eslint src && spago build --purs-args '--censor-lib --strict'"
+ "test:watch": "watchexec -e purs,js,yaml,rb -- spago bundle --outfile output/bundle.js --module Test.Main && mocha output/bundle.js",
+ "clean": "rm -rfd output output-es .spago dist",
+ "build": "rm -rdf dist && eslint src && spago build --censor-stats --strict --ensure-ranges --pedantic-packages && vite build",
+ "format": "purs-tidy format-in-place src test",
+ "check": "purs-tidy check src test",
+ "test": "spago test",
+ "update-docs": "spago docs --format markdown",
+ "production:build": "spago build && purs-backend-es build && vite build",
+ "production:preview": "vite preview --open",
+ "dev:vite": "vite dev --open",
+ "dev:spago": "watchexec -e purs,js,yaml -- spago build"
},
"devDependencies": {
- "eslint": "^7.6.0"
+ "@eslint/js": "^9.12.0",
+ "eslint": "^9.12.0",
+ "globals": "^15.11.0",
+ "mocha": "^10.7.3",
+ "mocha-headless-chrome": "^4.0.0",
+ "vite": "^5.4.0"
}
}
diff --git a/packages.dhall b/packages.dhall
deleted file mode 100644
index 582d6d3..0000000
--- a/packages.dhall
+++ /dev/null
@@ -1,4 +0,0 @@
-let upstream =
- https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall
-
-in upstream
diff --git a/run_tests.sh b/run_tests.sh
new file mode 100755
index 0000000..0e379a2
--- /dev/null
+++ b/run_tests.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+set -e
+
+npm run build
+
+mocha-headless-chrome --file dist/index.html --out output/test-output-headless.txt --args disable-web-security --args no-sandbox --executablePath chromium --visible --timeout 9999999
+
+# or open to debug
+#
+# chromium --disable-web-security --no-sandbox --disable-gpu --args --allow-file-access-from-files --user-data-dir=/tmp/chrome_dev_test dist/index.html
diff --git a/spago.dhall b/spago.dhall
deleted file mode 100644
index 7cf4966..0000000
--- a/spago.dhall
+++ /dev/null
@@ -1,5 +0,0 @@
-{ name = "affjax-web"
-, dependencies = [ "aff", "affjax", "maybe", "either", "prelude" ]
-, packages = ./packages.dhall
-, sources = [ "src/**/*.purs" ]
-}
diff --git a/spago.yaml b/spago.yaml
new file mode 100644
index 0000000..41a7bf6
--- /dev/null
+++ b/spago.yaml
@@ -0,0 +1,26 @@
+package:
+ name: affjax-web
+ description: An asynchronous AJAX library built using Aff that runs on the browser.
+ publish:
+ license: Apache-2.0
+ version: 2.0.0
+ location:
+ githubOwner: purescript-contrib
+ githubRepo: purescript-affjax-web
+ dependencies:
+ - aff: ">=8.0.0 <9.0.0"
+ - affjax: ">=13.0.0 <14.0.0"
+ - either: ">=6.1.0 <7.0.0"
+ - maybe: ">=6.0.0 <7.0.0"
+ - prelude: ">=6.0.1 <7.0.0"
+ test:
+ main: Test.Main
+ dependencies:
+ - console
+ - effect
+ - exceptions
+ - spec
+ - spec-mocha
+ - transformers
+ - unsafe-coerce
+workspace: {}
diff --git a/test/Test/Main.purs b/test/Test/Main.purs
new file mode 100644
index 0000000..5ad8705
--- /dev/null
+++ b/test/Test/Main.purs
@@ -0,0 +1,38 @@
+module Test.Main where
+
+import Prelude
+
+import Affjax.ResponseFormat as ResponseFormat
+import Affjax.Web as AX
+import Control.Monad.Error.Class (throwError)
+import Data.Either (Either(..))
+import Effect (Effect)
+import Effect.Aff (Aff)
+import Effect.Class (class MonadEffect)
+import Effect.Class.Console (log)
+import Effect.Exception (error)
+import Test.Spec (it)
+import Test.Spec.Assertions (fail)
+import Test.Spec.Mocha (runMocha)
+import Unsafe.Coerce (unsafeCoerce)
+
+logAny' :: forall a m. MonadEffect m => a -> m Unit
+logAny' = log <<< unsafeCoerce
+
+assertRight :: forall a b. Either a b -> Aff b
+assertRight = case _ of
+ Left y -> logAny' y *> throwError (error "Expected a Right value")
+ Right y -> pure y
+
+assertLeft :: forall a b. Either a b -> Aff a
+assertLeft x = case x of
+ Right y -> logAny' y *> throwError (error "Expected a Left value")
+ Left y -> pure y
+
+main :: Effect Unit
+main = runMocha do
+ it "Testing invalid url" do
+ res <- AX.get ResponseFormat.string "/фіва шхххх"
+ assertLeft res >>= case _ of
+ AX.RequestFailedError -> pure unit
+ other -> logAny' other *> fail "Expected a RequestFailedError"
diff --git a/vite.config.js b/vite.config.js
new file mode 100644
index 0000000..7174f61
--- /dev/null
+++ b/vite.config.js
@@ -0,0 +1,41 @@
+import * as path from "node:path";
+// import * as fs from 'node:fs'
+// import * as yaml from 'js-yaml'
+
+// Read and parse the YAML file
+// const spagoYamlFilePath = path.resolve(__dirname, 'spago.yaml');
+// const spagoYamlFileContent = fs.readFileSync(spagoYamlFilePath, 'utf8');
+// const data = yaml.load(spagoYamlFileContent);
+
+export default {
+ // Why base is empty?
+ //
+ // if undefined - it outputs
+ //
+ //
+ //
+ //
+ // if "" - changes to relative paths
+ //
+ //
+ //
+ // base: `/${data.package.publish.location.githubRepo}/`,
+ base: ``,
+
+ root: path.resolve(__dirname, "browser"),
+ build: {
+ outDir: path.resolve(__dirname, "dist"),
+ minify: false, // for debug
+ emptyOutDir: true, // prevent `outDir .../dist is not inside project root and will not be emptied.`
+ },
+ // mode: 'development', // still be minimified, option used if You want to `vite dev` (with a watching)
+ resolve: {
+ alias: {
+ // PureScript: process.env.NODE_ENV === "production"
+ // ? path.resolve(__dirname, "output-es")
+ // : path.resolve(__dirname, "output"),
+ node_modules: path.resolve(__dirname, "node_modules"),
+ PureScript: path.resolve(__dirname, "output"),
+ },
+ }
+};