@financial-times/dotcom-middleware-asset-loader 7.3.0 → 7.3.2

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/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@financial-times/dotcom-middleware-asset-loader",
3
- "version": "7.3.0",
3
+ "version": "7.3.2",
4
4
  "description": "",
5
5
  "main": "dist/node/index.js",
6
6
  "types": "src/index.ts",
7
7
  "scripts": {
8
8
  "test": "echo \"Error: no test specified\" && exit 1",
9
- "tsc": "../../node_modules/.bin/tsc --incremental",
10
9
  "clean": "npm run clean:dist && npm run clean:node_modules",
11
10
  "clean:dist": "rm -rf dist",
12
11
  "clean:node_modules": "rm -rf node_modules",
12
+ "build:node": "tsc",
13
13
  "build": "npm run build:node",
14
- "build:node": "npm run tsc -- --module commonjs --outDir ./dist/node",
15
14
  "dev": "npm run build:node -- --watch",
16
15
  "preinstall": "[ \"$INIT_CWD\" != \"$PWD\" ] || npm_config_yes=true npx check-engine"
17
16
  },
@@ -19,7 +18,7 @@
19
18
  "author": "",
20
19
  "license": "MIT",
21
20
  "dependencies": {
22
- "@financial-times/dotcom-server-asset-loader": "^7.3.0",
21
+ "@financial-times/dotcom-server-asset-loader": "file:../../packages/dotcom-server-asset-loader",
23
22
  "express": "^4.16.4"
24
23
  },
25
24
  "devDependencies": {
@@ -32,6 +31,10 @@
32
31
  "node": ">= 14.0.0",
33
32
  "npm": "7.x || 8.x"
34
33
  },
34
+ "files": [
35
+ "dist/",
36
+ "src/"
37
+ ],
35
38
  "repository": {
36
39
  "type": "git",
37
40
  "repository": "https://github.com/Financial-Times/dotcom-page-kit.git",
@@ -41,4 +44,4 @@
41
44
  "volta": {
42
45
  "extends": "../../package.json"
43
46
  }
44
- }
47
+ }
@@ -0,0 +1,35 @@
1
+ import subject from '../createMiddleware'
2
+ import httpMocks from 'node-mocks-http'
3
+
4
+ let instance
5
+ let request
6
+ let response
7
+ let next
8
+
9
+ jest.mock('@financial-times/dotcom-server-asset-loader')
10
+
11
+ describe('dotcom-middleware-asset-loader/src/createMiddleware', () => {
12
+ beforeEach(() => {
13
+ instance = subject({})
14
+ request = httpMocks.createRequest({ app: { locals: {} } })
15
+ response = httpMocks.createResponse()
16
+ next = jest.fn()
17
+ })
18
+
19
+ afterEach(() => {
20
+ instance = null
21
+ request = null
22
+ response = null
23
+ next = null
24
+ })
25
+
26
+ it('calls the fallthrough function', () => {
27
+ instance(request, response, next)
28
+ expect(next).toHaveBeenCalled()
29
+ })
30
+
31
+ it('adds an instance of the asset loader to response.locals', () => {
32
+ instance(request, response, next)
33
+ expect(response.locals.assetLoader).toBeDefined()
34
+ })
35
+ })
@@ -0,0 +1,42 @@
1
+ import { init } from '../index'
2
+
3
+ let instanceWithStaticHost
4
+ let instanceNoStaticHost
5
+
6
+ jest.mock('@financial-times/dotcom-server-asset-loader')
7
+
8
+ describe('dotcom-middleware-asset-loader', () => {
9
+ beforeEach(() => {
10
+ instanceWithStaticHost = init({ hostStaticAssets: true })
11
+ instanceNoStaticHost = init({ hostStaticAssets: false })
12
+ })
13
+
14
+ afterEach(() => {
15
+ instanceWithStaticHost = null
16
+ instanceNoStaticHost = null
17
+ })
18
+
19
+ it('returns an array of handler functions', () => {
20
+ expect(instanceWithStaticHost).toBeInstanceOf(Array)
21
+
22
+ instanceWithStaticHost.forEach((item) => {
23
+ expect(item).toBeInstanceOf(Function)
24
+ })
25
+ })
26
+
27
+ describe('with hostStaticAssets enabled', () => {
28
+ it('returns multiple handlers', () => {
29
+ expect(instanceWithStaticHost).toHaveLength(2)
30
+ })
31
+
32
+ it('returns an instance of the router', () => {
33
+ expect(instanceWithStaticHost[1].name).toEqual('router')
34
+ })
35
+ })
36
+
37
+ describe('without hostStaticAssets enabled', () => {
38
+ it('returns one handler', () => {
39
+ expect(instanceNoStaticHost).toHaveLength(1)
40
+ })
41
+ })
42
+ })