Browse Source

test(client): Add framework.

jackyalcine 11 months ago
parent
commit
b978bc8351
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 36CD7728BDFD66FF

+ 28
- 30
.postcssrc.js View File

@@ -4,9 +4,9 @@ const path = require('path');
4 4
 module.exports = {
5 5
   parser: 'postcss-scss',
6 6
   plugins: {
7
-    'postcss-reporter': {
8
-      clearMessages: false
9
-    },
7
+    // 'postcss-reporter': {
8
+    //   clearMessages: false
9
+    // },
10 10
     'postcss-url': [
11 11
       {
12 12
         url: 'copy',
@@ -15,32 +15,30 @@ module.exports = {
15 15
         useHash: false
16 16
       },
17 17
     ],
18
-    autoprefixer: {},
19
-    pixrem: {},
20
-    'postcss-combine-duplicated-selectors': {},
21
-    'postcss-light-text': {},
22
-    'postcss-reporter': {},
23
-    'postcss-ordered-values': {},
24
-    'postcss-reduce-initial': {},
25
-    'postcss-strip-inline-comments': {},
26
-    'postcss-pxtorem': {},
27
-    cssnano: ENV === 'production' ? {
28
-      preset: [
29
-        'default',
30
-        {
31
-          calc: true,
32
-          colormin: true,
33
-          discardUnused: true,
34
-          normalizeUrl: true
35
-        }
36
-      ]
37
-    } : false,
38
-    'postcss-pxtorem': {
39
-      unitPrecision: 4,
40
-      propWhiteList: [],
41
-      replace: true,
42
-      selectorBlackList: [],
43
-      minPixelValue: 4
44
-    },
18
+    // autoprefixer: {},
19
+    // 'postcss-combine-duplicated-selectors': {},
20
+    // 'postcss-light-text': {},
21
+    // 'postcss-reporter': {},
22
+    // 'postcss-ordered-values': {},
23
+    // 'postcss-reduce-initial': {},
24
+    // 'postcss-strip-inline-comments': {},
25
+    // 'postcss-pxtorem': {
26
+    //   unitPrecision: 4,
27
+    //   propWhiteList: [],
28
+    //   replace: true,
29
+    //   selectorBlackList: [],
30
+    //   minPixelValue: 4
31
+    // },
32
+    // cssnano: ENV === 'production' ? {
33
+    //   preset: [
34
+    //     'default',
35
+    //     {
36
+    //       calc: true,
37
+    //       colormin: true,
38
+    //       discardUnused: true,
39
+    //       normalizeUrl: true
40
+    //     }
41
+    //   ]
42
+    // } : false
45 43
   }
46 44
 };

+ 3
- 3
docker/scripts/docker-build.sh View File

@@ -1,8 +1,5 @@
1 1
 #!/bin/sh
2 2
 
3
-echo " ---> [npm] Pulling dependencies..."
4
-npm install || exit 50
5
-
6 3
 echo " ---> [mix] Preparing..."
7 4
 mix local.hex --force || exit 10
8 5
 mix local.rebar --force || exit 10
@@ -11,6 +8,9 @@ echo " ---> [mix] Fetching dependencies..."
11 8
 mix deps.clean --all || exit 20
12 9
 mix deps.get || exit 21
13 10
 
11
+echo " ---> [npm] Pulling dependencies..."
12
+npm install || exit 50
13
+
14 14
 echo " ---> [mix] Building dependencies..."
15 15
 mix deps.compile || exit 30
16 16
 

+ 8
- 0
jest.config.js View File

@@ -0,0 +1,8 @@
1
+const {defaults} = require('jest-config');
2
+
3
+module.exports =  {
4
+  verbose: true,
5
+  preset: 'ts-jest',
6
+  moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts'],
7
+  notify: true
8
+};

+ 0
- 1
mix.exs View File

@@ -102,7 +102,6 @@ defmodule Koype.Mixfile do
102 102
       {:sqlite_ecto2, "~> 2.2.5"},
103 103
       {:sweet_xml, "~> 0.6"},
104 104
       {:totpex, "~> 0.1.2"},
105
-      {:trailing_format_plug, "~> 0.0.5"},
106 105
       {:uuid, "~> 1.1"},
107 106
       {:ex_url, "~> 1.0.0"},
108 107
       {:ex_cldr, "~> 2.0"},

+ 2918
- 37
package-lock.json
File diff suppressed because it is too large
View File


+ 9
- 4
package.json View File

@@ -4,12 +4,13 @@
4 4
   "description": "A single-tenant IndieWeb platform.",
5 5
   "main": "index.js",
6 6
   "directories": {
7
-    "lib": "lib",
8
-    "test": "test"
7
+    "lib": "priv/static",
8
+    "test": "test/web"
9 9
   },
10 10
   "scripts": {
11
-    "parcel:watch": "parcel watch web/static/koype.ts --out-dir priv/static --cache-dir tmp/parcel",
12
-    "parcel:build": "parcel build web/static/koype.ts web/static/koype.scss --out-dir priv/static --cache-dir tmp/parcel --log-level 4 --detailed-report"
11
+    "parcel:watch": "parcel watch web/static/js/koype.ts web/static/css/koype.scss --out-dir priv/static/assets --cache-dir tmp/parcel --no-cache",
12
+    "parcel:build": "parcel build web/static/js/koype.ts web/static/css/koype.scss --out-dir priv/static/assets --cache-dir tmp/parcel --no-cache --log-level 4 --detailed-report",
13
+    "test": "jest"
13 14
   },
14 15
   "repository": {
15 16
     "type": "git",
@@ -38,6 +39,7 @@
38 39
     "sweet-alert": "^2.0.5",
39 40
     "tachyons": "4.10.0",
40 41
     "tachyons-sass": "4.9.5",
42
+    "ts-node": "7.0.1",
41 43
     "typeface-source-code-pro": "0.0.54",
42 44
     "typeface-source-sans-pro": "0.0.54",
43 45
     "typeface-source-serif-pro": "0.0.54",
@@ -48,6 +50,8 @@
48 50
     "npm": "6.4.0"
49 51
   },
50 52
   "devDependencies": {
53
+    "@types/jest": "23.3.10",
54
+    "jest": "23.6.0",
51 55
     "parcel-plugin-bundle-visualiser": "1.2.0",
52 56
     "postcss-hash": "^1.0.2",
53 57
     "postcss-import": "12.0.1",
@@ -58,6 +62,7 @@
58 62
     "stylelint": "9.9.0",
59 63
     "stylelint-config-recommended-scss": "3.2.0",
60 64
     "stylelint-scss": "3.4.0",
65
+    "ts-jest": "23.10.5",
61 66
     "typescript": "^3.2.1"
62 67
   }
63 68
 }

BIN
priv/static/images/favicon.png View File


BIN
priv/static/images/phoenix.png View File


+ 5
- 0
tsconfig.json View File

@@ -0,0 +1,5 @@
1
+{
2
+  "compilerOptions": {
3
+    "lib": ["es6", "dom"]
4
+  }
5
+}

+ 0
- 10
web/endpoint.ex View File

@@ -4,14 +4,6 @@ defmodule Koype.Web.Endpoint do
4 4
 
5 5
   socket("/socket", Koype.Web.UserSocket)
6 6
 
7
-  plug(
8
-    Plug.Static,
9
-    at: "/assets",
10
-    from: :koype,
11
-    gzip: :true,
12
-    only_matching: ~w(koype source)
13
-  )
14
-
15 7
   plug(
16 8
     Plug.Static,
17 9
     at: "/",
@@ -45,8 +37,6 @@ defmodule Koype.Web.Endpoint do
45 37
     extra: "SameSite=Strict"
46 38
   )
47 39
 
48
-  plug(TrailingFormatPlug)
49
-
50 40
   plug(Koype.Web.Router)
51 41
 
52 42
   def init(_key, config) do

web/static/koype.scss → web/static/css/koype.scss View File


+ 3
- 0
web/static/js/koype.test.ts View File

@@ -0,0 +1,3 @@
1
+test('adds 1 + 2 to equal 3', () => {
2
+  expect(1 + 2).toBe(3);
3
+});

web/static/koype.ts → web/static/js/koype.ts View File

@@ -37,10 +37,8 @@ function handleLinkClick(link) {
37 37
 }
38 38
 
39 39
 window.addEventListener("click", function(e) {
40
-  if (e.target) {
41
-    const elem: Element = e.target;
42
-    if (elem.getAttribute("data-method")) {
43
-      handleLinkClick(elem);
40
+  if (e.target && e.target.getAttribute("data-method")) {
41
+      handleLinkClick(e.target);
44 42
     }
45 43
   }
46 44
 }, false);
@@ -56,4 +54,4 @@ window.addEventListener('load', function() {
56 54
       sessionStorage.fonts = true;
57 55
     }
58 56
   });
59
-});
57
+}, false);

+ 3
- 9
web/templates/layout/app.html.eex View File

@@ -3,24 +3,18 @@
3 3
   <head>
4 4
     <meta charset="utf-8">
5 5
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
-    <base href="<%= Koype.host %>" target="_self">
7
-
8
-    <!-- Metadata -->
9 6
     <%= for name <- Koype.Web.tags(:meta) ++ @view_module.tags(:meta, @view_template, assigns) do %>
10 7
       <meta name="<%= name %>" content="<%= @view_module.tag({:meta, name}, @view_template, assigns) %>" />
11 8
     <% end %>
12 9
     <meta name="viewport" content="initial-scale=1.0,user-scalable=yes,maximum-scale=1,width=device-width,height=device-height" />
10
+    <base href="<%= Koype.host %>" target="_self">
13 11
     <title><%= @view_module.title(@view_template, assigns) %> - <%= base_title() %></title>
14
-
15
-    <!-- IndieWeb bits -->
16 12
     <%= for name <- Koype.Web.tags(:link) ++ @view_module.tags(:link, @view_template, assigns) do %>
17 13
       <link rel="<%= name %>" href="<%= @view_module.tag({:link, name}, @view_template, assigns) %>" />
18 14
     <% end %>
19 15
     <link rel="icon" type="image/png" href="<%= static_path(@conn, "/images/favicon.png") %>" sizes="100x100" />
20 16
     <link rel="icon" type="image/x-icon" href="<%= static_path(@conn, "/images/favicon.png") %>" />
21
-
22
-    <!-- Styling -->
23
-    <link rel="stylesheet" href="<%= static_path(@conn, "/assets/koype.css") %>" />
17
+    <link rel="stylesheet" href="<%= static_path(@conn, "/assets/css/koype.css") %>" />
24 18
   </head>
25 19
   <body class="w-100 min-h-100 min-vh-100 flex flex-column near-black bg-near-white sans-serif">
26 20
     <%= render Koype.Web.PageView, "_header.html", assigns %>
@@ -30,6 +24,6 @@
30 24
     </main>
31 25
     <%= render Koype.Web.PageView, "_now-sparkline.html", assigns %>
32 26
     <%= render Koype.Web.PageView, "_footer.html", assigns %>
33
-    <script async defer src="<%= static_path(@conn, "/assets/koype.js") %>"></script>
27
+    <script async defer src="<%= static_path(@conn, "/assets/js/koype.js") %>"></script>
34 28
   </body>
35 29
 </html>

Loading…
Cancel
Save