@financial-times/dotcom-ui-flags 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/dist/browser/client/Flags.d.ts +7 -0
- package/dist/browser/client/index.d.ts +4 -0
- package/dist/browser/client/loadFlags.d.ts +2 -0
- package/dist/browser/components/FlagsEmbed.d.ts +13 -0
- package/dist/browser/constants.d.ts +1 -0
- package/dist/browser/index.d.ts +2 -0
- package/dist/browser/server/formatFlagsJSON.d.ts +2 -0
- package/dist/browser/server/index.d.ts +2 -0
- package/dist/node/client/Flags.d.ts +7 -0
- package/dist/node/client/index.d.ts +4 -0
- package/dist/node/client/loadFlags.d.ts +2 -0
- package/dist/node/components/FlagsEmbed.d.ts +13 -0
- package/dist/node/constants.d.ts +1 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/server/formatFlagsJSON.d.ts +2 -0
- package/dist/node/server/index.d.ts +2 -0
- package/dist/tsconfig.tsbuildinfo +2110 -0
- package/package.json +12 -6
- package/src/__test__/client/Flags.spec.ts +32 -0
- package/src/__test__/client/loadFlags.spec.ts +36 -0
- package/src/__test__/components/FlagsEmbed.spec.ts +14 -0
- package/src/__test__/components/__snapshots__/FlagsEmbed.spec.ts.snap +13 -0
- package/src/__test__/server/formatFlagsJSON.spec.ts +10 -0
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@financial-times/dotcom-ui-flags",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "component.js",
|
|
6
6
|
"browser": "browser.js",
|
|
7
7
|
"types": "src/index.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
|
-
"tsc": "../../node_modules/.bin/tsc --incremental",
|
|
11
10
|
"clean": "npm run clean:dist && npm run clean:node_modules",
|
|
12
11
|
"clean:dist": "rm -rf dist",
|
|
13
12
|
"clean:node_modules": "rm -rf node_modules",
|
|
14
13
|
"clean:install": "npm run clean && npm i",
|
|
15
|
-
"build:
|
|
16
|
-
"build:
|
|
14
|
+
"build:browser": "tsc --module es2015 --outDir ./dist/browser",
|
|
15
|
+
"build:node": "tsc",
|
|
17
16
|
"build": "npm run build:node && npm run build:browser",
|
|
18
17
|
"dev": "echo -n node browser | parallel -u -d ' ' npm run build:{} -- --watch",
|
|
19
18
|
"preinstall": "[ \"$INIT_CWD\" != \"$PWD\" ] || npm_config_yes=true npx check-engine"
|
|
@@ -26,11 +25,18 @@
|
|
|
26
25
|
"npm": "7.x || 8.x"
|
|
27
26
|
},
|
|
28
27
|
"dependencies": {
|
|
29
|
-
"@financial-times/dotcom-ui-data-embed": "
|
|
28
|
+
"@financial-times/dotcom-ui-data-embed": "file:../dotcom-ui-data-embed"
|
|
30
29
|
},
|
|
31
30
|
"peerDependencies": {
|
|
32
31
|
"react": "16.x || 17.x"
|
|
33
32
|
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/",
|
|
35
|
+
"src/",
|
|
36
|
+
"browser.js",
|
|
37
|
+
"component.js",
|
|
38
|
+
"server.js"
|
|
39
|
+
],
|
|
34
40
|
"repository": {
|
|
35
41
|
"type": "git",
|
|
36
42
|
"repository": "https://github.com/Financial-Times/dotcom-page-kit.git",
|
|
@@ -44,4 +50,4 @@
|
|
|
44
50
|
"check-engine": "^1.10.1",
|
|
45
51
|
"react": "^16.8.6"
|
|
46
52
|
}
|
|
47
|
-
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Subject from '../../client/Flags'
|
|
2
|
+
|
|
3
|
+
const fixture = { foo: 1, bar: true }
|
|
4
|
+
|
|
5
|
+
describe('dotcom-ui-flags/src/client/Flags', () => {
|
|
6
|
+
let instance
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
instance = new Subject(fixture)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
describe('.get()', () => {
|
|
13
|
+
it('returns the value of a flag which exists', () => {
|
|
14
|
+
expect(instance.get('foo')).toBe(1)
|
|
15
|
+
expect(instance.get('bar')).toBe(true)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('returns undefined for flags which do not exist', () => {
|
|
19
|
+
expect(instance.get('baz')).toBeUndefined()
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe('.getAll()', () => {
|
|
24
|
+
it('returns all flags data', () => {
|
|
25
|
+
expect(instance.getAll()).toEqual(fixture)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('freezes the flags data', () => {
|
|
29
|
+
expect(Object.isFrozen(instance.getAll())).toBe(true)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import subject from '../../client/loadFlags'
|
|
6
|
+
import { SCRIPT_ELEMENT_ID } from '../../constants'
|
|
7
|
+
|
|
8
|
+
describe('dotcom-ui-flags/src/client/loadFlags', () => {
|
|
9
|
+
describe('when there is a configuration object', () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
document.body.innerHTML = `
|
|
12
|
+
<script id="${SCRIPT_ELEMENT_ID}">{"foo":1,"bar":true,"baz":"qux"}</script>
|
|
13
|
+
`
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('returns a frozen object', () => {
|
|
17
|
+
const result = subject()
|
|
18
|
+
|
|
19
|
+
expect(result).toEqual({ foo: 1, bar: true, baz: 'qux' })
|
|
20
|
+
expect(Object.isFrozen(result)).toBe(true)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('when there is no a configuration object', () => {
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
document.body.innerHTML = ''
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('returns a frozen empty object', () => {
|
|
30
|
+
const result = subject()
|
|
31
|
+
|
|
32
|
+
expect(result).toEqual({})
|
|
33
|
+
expect(Object.isFrozen(result)).toBe(true)
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import renderer from 'react-test-renderer'
|
|
2
|
+
import { FlagsEmbed as subject } from '../../components/FlagsEmbed'
|
|
3
|
+
|
|
4
|
+
const flags = {
|
|
5
|
+
foo: 1,
|
|
6
|
+
baz: 'qux'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('dotcom-ui-flags/src/components/FlagsEmbed', () => {
|
|
10
|
+
it('renders a script element containing flags', () => {
|
|
11
|
+
const tree = renderer.create(subject({ flags }))
|
|
12
|
+
expect(tree).toMatchSnapshot()
|
|
13
|
+
})
|
|
14
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`dotcom-ui-flags/src/components/FlagsEmbed renders a script element containing flags 1`] = `
|
|
4
|
+
<script
|
|
5
|
+
dangerouslySetInnerHTML={
|
|
6
|
+
Object {
|
|
7
|
+
"__html": "{\\"foo\\":1,\\"baz\\":\\"qux\\"}",
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
id="page-kit-flags-embed"
|
|
11
|
+
type="application/json"
|
|
12
|
+
/>
|
|
13
|
+
`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import subject from '../../server/formatFlagsJSON'
|
|
2
|
+
|
|
3
|
+
const fixture = Object.freeze({ foo: 1, bar: false, baz: 'qux' })
|
|
4
|
+
|
|
5
|
+
describe('dotcom-ui-flags/src/server/formatFlagsJSON', () => {
|
|
6
|
+
it('filters out properties with falsey values', () => {
|
|
7
|
+
const result = subject(fixture)
|
|
8
|
+
expect(result).toStrictEqual({ foo: 1, baz: 'qux' })
|
|
9
|
+
})
|
|
10
|
+
})
|