@toptal/davinci-qa 5.0.2-alpha-fx-2156-improve-build-performance.1302 → 5.0.2-alpha-tph-1237-github-test-results.1304

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/README.md CHANGED
@@ -17,6 +17,8 @@ To run jest tests with your config file just go to the root directory of your pr
17
17
  Options:
18
18
 
19
19
  - `--setupFilesAfterEnv` - a list of paths to global configuration files for jest tests
20
+ - `--inspect` - start test run in inspect mode, allowing the dev tools to be attached to the test runner process. Read more at [Profiling Unit Tests](https://toptal-core.atlassian.net/wiki/spaces/FE/pages/1446379739/Profiling+Unit+Tests).
21
+ - `--tag <project-tag>` - the project name matching [Anvil's expected tag](https://github.com/toptal/anvil/blob/2ea49649db605fc06492fcf346bdb0c56fff0769/app/models/test_result.rb#L10). Used to generate Anvil Reports.
20
22
  - Any other jest option (ex. `--runInBand`)
21
23
 
22
24
  [Jest CLI docs](https://jestjs.io/docs/en/cli)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-qa",
3
- "version": "5.0.2-alpha-fx-2156-improve-build-performance.1302+4dbc440",
3
+ "version": "5.0.2-alpha-tph-1237-github-test-results.1304+6d6284a",
4
4
  "description": "QA package to test your application",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -36,7 +36,7 @@
36
36
  "@cypress/webpack-preprocessor": "^5.7.0",
37
37
  "@testing-library/jest-dom": "^5.14.1",
38
38
  "@testing-library/react": "^12.0.0",
39
- "@toptal/davinci-cli-shared": "1.4.2-alpha-fx-2156-improve-build-performance.1302+4dbc440",
39
+ "@toptal/davinci-cli-shared": "1.4.2-alpha-tph-1237-github-test-results.1304+6d6284a",
40
40
  "@types/jest": "^26.0.15",
41
41
  "babel-jest": "^26.3.0",
42
42
  "cypress": "^8.6.0",
@@ -50,5 +50,5 @@
50
50
  "matchmedia-polyfill": "^0.3.2",
51
51
  "semver": "^7.3.2"
52
52
  },
53
- "gitHead": "4dbc440ef664502a9b5c91a33fe52a5602bd8a97"
53
+ "gitHead": "6d6284a28181286e0dab3ed19369710f62a8b7eb"
54
54
  }
@@ -1,11 +1,13 @@
1
1
  const { print, files } = require('@toptal/davinci-cli-shared')
2
2
  const jest = require('jest')
3
+ const path = require('path')
3
4
 
4
5
  const excludedFilesFromCoverage = require('../configs/excludeFilesFromCoverage')
5
6
  const styledComponentsVersionCheck = require('../utils/styled-components-version-check')
6
7
  const toJestCLIArguments = require('../utils/to-jest-cli-arguments')
8
+ const getAbsolutePath = relativePath => path.join(__dirname, relativePath)
7
9
 
8
- const defaultCIJestReporters = [
10
+ const defaultCIJestReporters = (tag) => [
9
11
  [
10
12
  'jest-silent-reporter', {
11
13
  'useDots': true,
@@ -21,11 +23,16 @@ const defaultCIJestReporters = [
21
23
  'jest-html-reporters', {
22
24
  'publicPath': './reports',
23
25
  }
26
+ ],
27
+ [
28
+ getAbsolutePath('../reporters/jest-anvil-reporter.js'), {
29
+ 'tag': tag
30
+ }
24
31
  ]
25
32
  ]
26
33
 
27
34
  const unitTestsCommand = ({
28
- options: { inspect = false, ...jestOptions } = {},
35
+ options: { inspect = false, tag, ...jestOptions } = {},
29
36
  files: testPathPattern = []
30
37
  }) => {
31
38
  print.green('Running unit tests...')
@@ -62,9 +69,12 @@ const unitTestsCommand = ({
62
69
 
63
70
  // to show smaller log of tests running on CI
64
71
  // and a nicer html report
65
- defaultOptions.reporters = jestOptions.reporters
66
- ? jestOptions.reporters
67
- : defaultCIJestReporters
72
+ if (jestOptions.reporters) {
73
+ defaultOptions.reporters = jestOptions.reporters
74
+ } else {
75
+ defaultOptions.testLocationInResults = true // allows reporters to return test line number
76
+ defaultOptions.reporters = defaultCIJestReporters(tag)
77
+ }
68
78
  }
69
79
 
70
80
  const options = {
@@ -96,7 +106,12 @@ const unitTestsCommandCreator = {
96
106
  },
97
107
  {
98
108
  label:
99
- 'Start in the inspect mode allowing dev tools to be attached to the test runner process. Read more at https://toptal-core.atlassian.net/wiki/spaces/FE/pages/1446379739/Profiling+Unit+Tests.',
109
+ 'the project name matching Anvil\'s expected tag. Used to generate Anvil-compatible test reports.',
110
+ name: '--tag <tag>'
111
+ },
112
+ {
113
+ label:
114
+ 'start the test run in inspect mode, allowing dev tools to be attached to the test runner process. Read more at https://toptal-core.atlassian.net/wiki/spaces/FE/pages/1446379739/Profiling+Unit+Tests.',
100
115
  name: '--inspect'
101
116
  }
102
117
  ]
@@ -0,0 +1,50 @@
1
+ const { print } = require('@toptal/davinci-cli-shared')
2
+ const fs = require('fs')
3
+
4
+ class JestAnvilReporter {
5
+ constructor(globalConfig, options) {
6
+ this._globalConfig = globalConfig
7
+ this._options = options
8
+ }
9
+
10
+ onRunComplete(contexts, results) {
11
+ print.grey('Starting Anvil processing...')
12
+ console.time('Anvil reporter run')
13
+ const fileTestResults = results.testResults
14
+ const runPath = process.cwd()
15
+ const individualTestResults = fileTestResults.flatMap(fileTestResult => {
16
+ const fileName = fileTestResult.testFilePath.replace(runPath, '.')
17
+ return fileTestResult.testResults.map(res => ({ ...res, fileName }))
18
+ })
19
+ const anvilTestResults = individualTestResults.map(testResult => {
20
+ const results = {
21
+ file_name: testResult.fileName,
22
+ line_number: testResult.location.line,
23
+ status: testResult.status,
24
+ duration: testResult.duration,
25
+ scenario_name: testResult.ancestorTitles.concat(testResult.title).join('/'),
26
+ description: testResult.title,
27
+ error: testResult.failureDetails.length > 0 ? testResult.failureDetails[0].message : null,
28
+ backtrace: testResult.failureDetails.length > 0 ? testResult.failureDetails[0].stack : null,
29
+ }
30
+ if (this._options.tag) {
31
+ results['tag'] = this._options.tag
32
+ }
33
+ return results
34
+ })
35
+ const anvilPayload = {
36
+ "test_results": [
37
+ anvilTestResults
38
+ ]
39
+ }
40
+ fs.writeFileSync('./anvil_test_results.json', JSON.stringify(anvilPayload, undefined, 2), err => {
41
+ if (err) {
42
+ print.red('Failed to create anvil test results', err)
43
+ throw err
44
+ }
45
+ })
46
+ console.timeEnd('Anvil reporter run')
47
+ }
48
+ }
49
+
50
+ module.exports = JestAnvilReporter
@@ -0,0 +1,111 @@
1
+ SUCCESS = {
2
+ numFailedTestSuites: 0,
3
+ numFailedTests: 0,
4
+ numPassedTestSuites: 3,
5
+ numPassedTests: 13,
6
+ numPendingTestSuites: 0,
7
+ numPendingTests: 0,
8
+ numRuntimeErrorTestSuites: 0,
9
+ numTodoTests: 0,
10
+ numTotalTestSuites: 3,
11
+ numTotalTests: 13,
12
+ openHandles: [
13
+ ],
14
+ snapshot: {
15
+ added: 0,
16
+ didUpdate: false,
17
+ failure: false,
18
+ filesAdded: 0,
19
+ filesRemoved: 0,
20
+ filesRemovedList: [
21
+ ],
22
+ filesUnmatched: 0,
23
+ filesUpdated: 0,
24
+ matched: 0,
25
+ total: 0,
26
+ unchecked: 0,
27
+ uncheckedKeysByFile: [
28
+ ],
29
+ unmatched: 0,
30
+ updated: 0,
31
+ },
32
+ startTime: 1635357418106,
33
+ success: false,
34
+ testResults: [
35
+ {
36
+ leaks: false,
37
+ numFailingTests: 0,
38
+ numPassingTests: 6,
39
+ numPendingTests: 0,
40
+ numTodoTests: 0,
41
+ openHandles: [
42
+ ],
43
+ perfStats: {
44
+ end: 1635357420742,
45
+ runtime: 1193,
46
+ slow: false,
47
+ start: 1635357419549,
48
+ },
49
+ skipped: false,
50
+ snapshot: {
51
+ added: 0,
52
+ fileDeleted: false,
53
+ matched: 0,
54
+ unchecked: 0,
55
+ unmatched: 0,
56
+ updated: 0,
57
+ uncheckedKeys: [
58
+ ],
59
+ },
60
+ testFilePath: "./packages/qa/src/utils/styled-components-version-check.test.js",
61
+ testResults: [
62
+ {
63
+ ancestorTitles: [
64
+ "styled-components version check",
65
+ "has wrong (^4.4.1) SC version in dependencies",
66
+ ],
67
+ duration: 7,
68
+ failureDetails: [
69
+ ],
70
+ failureMessages: [
71
+ ],
72
+ fullName: "styled-components version check has wrong (^4.4.1) SC version in dependencies should throw an error",
73
+ location: {
74
+ column: 4,
75
+ line: 44,
76
+ },
77
+ numPassingAsserts: 0,
78
+ status: "passed",
79
+ title: "should throw an error",
80
+ },
81
+ {
82
+ ancestorTitles: [
83
+ "styled-components version check",
84
+ "has correct (^5.0.1) SC version in dependencies",
85
+ ],
86
+ duration: 1,
87
+ failureDetails: [
88
+ ],
89
+ failureMessages: [
90
+ ],
91
+ fullName: "styled-components version check has correct (^5.0.1) SC version in dependencies should NOT throw an error",
92
+ location: {
93
+ column: 4,
94
+ line: 50,
95
+ },
96
+ numPassingAsserts: 0,
97
+ status: "passed",
98
+ title: "should NOT throw an error",
99
+ },
100
+ ],
101
+ console: undefined,
102
+ failureMessage: null,
103
+ displayName: undefined,
104
+ sourceMaps: undefined,
105
+ coverage: undefined,
106
+ }
107
+ ],
108
+ wasInterrupted: false,
109
+ }
110
+
111
+ module.exports = SUCCESS