@constl/utils-tests 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.aegir.js ADDED
@@ -0,0 +1,120 @@
1
+ import path, { dirname } from "path";
2
+ import { fileURLToPath } from "url";
3
+ import { createRequire } from "module";
4
+ import express from "express";
5
+ import cors from "cors";
6
+ import url from "url";
7
+
8
+ const require = createRequire(import.meta.url);
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
+
12
+ // https://github.com/node-webrtc/node-webrtc/issues/636#issuecomment-774171409
13
+ process.on("beforeExit", (code) => process.exit(code));
14
+
15
+ // https://github.com/ipfs/aegir/blob/master/md/migration-to-v31.md
16
+ const esbuild = {
17
+ // this will inject all the named exports from 'node-globals.js' as globals
18
+ inject: [path.join(__dirname, "./scripts/node-globals.js")],
19
+ external: [
20
+ "fs",
21
+ "path",
22
+ "os",
23
+ "chokidar",
24
+ "url",
25
+ "zlib",
26
+ "rimraf",
27
+ ],
28
+ plugins: [
29
+ {
30
+ name: "node built ins", // this will make the bundler resolve node builtins to the respective browser polyfill
31
+ setup(build) {
32
+ build.onResolve({ filter: /^stream$/ }, () => {
33
+ return { path: require.resolve("stream-browserify") };
34
+ });
35
+ build.onResolve({ filter: /^os$/ }, () => {
36
+ return { path: require.resolve("os-browserify") };
37
+ });
38
+ build.onResolve({ filter: /^crypto$/ }, () => {
39
+ return { path: require.resolve("crypto-browserify") };
40
+ });
41
+ build.onResolve({ filter: /^fs/ }, () => {
42
+ return { path: require.resolve("browserify-fs") };
43
+ });
44
+ },
45
+ },
46
+ ],
47
+ };
48
+
49
+ /** @type {import('aegir').PartialOptions} */
50
+ const options = {
51
+ test: {
52
+ browser: {
53
+ config: {
54
+ buildConfig: esbuild,
55
+ },
56
+ },
57
+ before: async (opts) => {
58
+
59
+ // On va lancer une page Constellation pour pouvoir tester la connectivité webrtc avec les navigateurs
60
+ const { chromium } = await import("playwright");
61
+ const navigateur = await chromium.launch();
62
+ try {
63
+ const page = await navigateur.newPage();
64
+ await page.goto("https://réseau-constellation.ca");
65
+ } catch (e) {
66
+ // On arrête pas les tests pour une petite erreur comme ça
67
+ console.error(e);
68
+ }
69
+
70
+ // Pour pouvoir accéder les fichiers test dans le navigateur
71
+ /**
72
+ * @type {Express | undefined}
73
+ */
74
+ let serveurLocal = undefined;
75
+
76
+ if (opts.target.includes('browser') || opts.target.includes('electron-renderer')) {
77
+ const appliExpress = express();
78
+
79
+ // Permettre l'accès à partir de l'hôte locale
80
+ appliExpress.use(cors({
81
+ origin: function (origin, callback) {
82
+ if (!origin) {
83
+ callback(null, true)
84
+ return;
85
+ }
86
+ if ((new URL(origin)).hostname === "127.0.0.1") {
87
+ callback(null, true)
88
+ } else {
89
+ callback(new Error('Not allowed by CORS'))
90
+ }
91
+ },
92
+ }));
93
+ appliExpress.get("/fichier/:nomFichier", function (req, res) {
94
+ const { nomFichier } = req.params
95
+
96
+ const cheminFichier = path.join(
97
+ url.fileURLToPath(new URL(".", import.meta.url)),
98
+ "test",
99
+ "ressources",
100
+ decodeURIComponent(nomFichier),
101
+ )
102
+
103
+ res.sendFile(cheminFichier)
104
+ })
105
+ serveurLocal = appliExpress.listen(3000);
106
+ }
107
+
108
+ return { navigateur, serveurLocal };
109
+ },
110
+ after: async (_, avant) => {
111
+ await avant.navigateur.close();
112
+ await avant.serveurLocal?.close()
113
+ },
114
+ },
115
+ build: {
116
+ config: esbuild,
117
+ },
118
+ };
119
+
120
+ export default options;
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ lib
3
+ docu
package/.eslintrc.cjs ADDED
@@ -0,0 +1,30 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es2021: true,
5
+ node: true,
6
+ },
7
+ extends: [
8
+ "eslint:recommended",
9
+ "plugin:@typescript-eslint/eslint-recommended",
10
+ "plugin:@typescript-eslint/recommended",
11
+ "prettier",
12
+ ],
13
+ parser: "@typescript-eslint/parser",
14
+ parserOptions: {
15
+ ecmaVersion: 12,
16
+ sourceType: "module",
17
+ },
18
+ plugins: ["@typescript-eslint"],
19
+ rules: {
20
+ "@typescript-eslint/no-non-null-assertion": "off",
21
+ "@typescript-eslint/no-unused-vars": [
22
+ "warn",
23
+ {
24
+ "argsIgnorePattern": "^_",
25
+ "varsIgnorePattern": "^_",
26
+ "caughtErrorsIgnorePattern": "^_"
27
+ }
28
+ ]
29
+ },
30
+ };