1 | 'use strict';
|
2 | const util = require('util');
|
3 | const ansiStyles = require('ansi-styles');
|
4 | const stripAnsi = require('strip-ansi');
|
5 | const cloneDeepWith = require('lodash/cloneDeepWith');
|
6 | const reactPlugin = require('@concordance/react');
|
7 | const chalk = require('./chalk').get();
|
8 |
|
9 |
|
10 |
|
11 | const avaReactPlugin = {...reactPlugin, name: 'ava-plugin-react'};
|
12 | const plugins = [avaReactPlugin];
|
13 |
|
14 | const forceColor = new chalk.Instance({level: Math.max(chalk.level, 1)});
|
15 |
|
16 | const colorTheme = {
|
17 | boolean: ansiStyles.yellow,
|
18 | circular: forceColor.grey('[Circular]'),
|
19 | date: {
|
20 | invalid: forceColor.red('invalid'),
|
21 | value: ansiStyles.blue
|
22 | },
|
23 | diffGutters: {
|
24 | actual: forceColor.red('-') + ' ',
|
25 | expected: forceColor.green('+') + ' ',
|
26 | padding: ' '
|
27 | },
|
28 | error: {
|
29 | ctor: {open: ansiStyles.grey.open + '(', close: ')' + ansiStyles.grey.close},
|
30 | name: ansiStyles.magenta
|
31 | },
|
32 | function: {
|
33 | name: ansiStyles.blue,
|
34 | stringTag: ansiStyles.magenta
|
35 | },
|
36 | global: ansiStyles.magenta,
|
37 | item: {after: forceColor.grey(',')},
|
38 | list: {openBracket: forceColor.grey('['), closeBracket: forceColor.grey(']')},
|
39 | mapEntry: {after: forceColor.grey(',')},
|
40 | maxDepth: forceColor.grey('…'),
|
41 | null: ansiStyles.yellow,
|
42 | number: ansiStyles.yellow,
|
43 | object: {
|
44 | openBracket: forceColor.grey('{'),
|
45 | closeBracket: forceColor.grey('}'),
|
46 | ctor: ansiStyles.magenta,
|
47 | stringTag: {open: ansiStyles.magenta.open + '@', close: ansiStyles.magenta.close},
|
48 | secondaryStringTag: {open: ansiStyles.grey.open + '@', close: ansiStyles.grey.close}
|
49 | },
|
50 | property: {
|
51 | after: forceColor.grey(','),
|
52 | keyBracket: {open: forceColor.grey('['), close: forceColor.grey(']')},
|
53 | valueFallback: forceColor.grey('…')
|
54 | },
|
55 | react: {
|
56 | functionType: forceColor.grey('\u235F'),
|
57 | openTag: {
|
58 | start: forceColor.grey('<'),
|
59 | end: forceColor.grey('>'),
|
60 | selfClose: forceColor.grey('/'),
|
61 | selfCloseVoid: ' ' + forceColor.grey('/')
|
62 | },
|
63 | closeTag: {
|
64 | open: forceColor.grey('</'),
|
65 | close: forceColor.grey('>')
|
66 | },
|
67 | tagName: ansiStyles.magenta,
|
68 | attribute: {
|
69 | separator: '=',
|
70 | value: {
|
71 | openBracket: forceColor.grey('{'),
|
72 | closeBracket: forceColor.grey('}'),
|
73 | string: {
|
74 | line: {open: forceColor.blue('"'), close: forceColor.blue('"'), escapeQuote: '"'}
|
75 | }
|
76 | }
|
77 | },
|
78 | child: {
|
79 | openBracket: forceColor.grey('{'),
|
80 | closeBracket: forceColor.grey('}')
|
81 | }
|
82 | },
|
83 | regexp: {
|
84 | source: {open: ansiStyles.blue.open + '/', close: '/' + ansiStyles.blue.close},
|
85 | flags: ansiStyles.yellow
|
86 | },
|
87 | stats: {separator: forceColor.grey('---')},
|
88 | string: {
|
89 | open: ansiStyles.blue.open,
|
90 | close: ansiStyles.blue.close,
|
91 | line: {open: forceColor.blue('\''), close: forceColor.blue('\'')},
|
92 | multiline: {start: forceColor.blue('`'), end: forceColor.blue('`')},
|
93 | controlPicture: ansiStyles.grey,
|
94 | diff: {
|
95 | insert: {
|
96 | open: ansiStyles.bgGreen.open + ansiStyles.black.open,
|
97 | close: ansiStyles.black.close + ansiStyles.bgGreen.close
|
98 | },
|
99 | delete: {
|
100 | open: ansiStyles.bgRed.open + ansiStyles.black.open,
|
101 | close: ansiStyles.black.close + ansiStyles.bgRed.close
|
102 | },
|
103 | equal: ansiStyles.blue,
|
104 | insertLine: {
|
105 | open: ansiStyles.green.open,
|
106 | close: ansiStyles.green.close
|
107 | },
|
108 | deleteLine: {
|
109 | open: ansiStyles.red.open,
|
110 | close: ansiStyles.red.close
|
111 | }
|
112 | }
|
113 | },
|
114 | symbol: ansiStyles.yellow,
|
115 | typedArray: {
|
116 | bytes: ansiStyles.yellow
|
117 | },
|
118 | undefined: ansiStyles.yellow
|
119 | };
|
120 |
|
121 | const plainTheme = cloneDeepWith(colorTheme, value => {
|
122 | if (typeof value === 'string') {
|
123 | return stripAnsi(value);
|
124 | }
|
125 | });
|
126 |
|
127 | const theme = chalk.level > 0 ? colorTheme : plainTheme;
|
128 |
|
129 | exports.default = {
|
130 |
|
131 | get maxDepth() {
|
132 | return Math.max(3, util.inspect.defaultOptions.depth);
|
133 | },
|
134 | plugins,
|
135 | theme
|
136 | };
|
137 |
|
138 | exports.snapshotManager = {plugins, theme: plainTheme};
|