@toptal/davinci-qa 5.5.1-alpha-fix-integration-tests-jenkins.6 → 5.6.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 5.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1208](https://github.com/toptal/davinci/pull/1208) [`893b5be1`](https://github.com/toptal/davinci/commit/893b5be12f1da8ccc5614e17cd705c348800d20d) Thanks [@rafael-anachoreta](https://github.com/rafael-anachoreta)! - Allow jest config reporters to override defaults
8
+
3
9
  ## 5.5.0
4
10
 
5
11
  ### Minor Changes
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@toptal/davinci-qa",
3
+ "version": "5.6.0",
4
+ "description": "QA package to test your application",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "keywords": [
9
+ "qa",
10
+ "testing"
11
+ ],
12
+ "author": "Toptal",
13
+ "homepage": "https://github.com/toptal/davinci/tree/master/packages/qa#readme",
14
+ "license": "ISC",
15
+ "bin": {
16
+ "davinci-qa": "./bin/davinci-qa.js"
17
+ },
18
+ "main": "./src/index.js",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/toptal/davinci.git"
22
+ },
23
+ "scripts": {
24
+ "build:package": "../../bin/build-package.js",
25
+ "prepublishOnly": "../../bin/prepublish.js",
26
+ "test": "echo \"Error: run tests from root\" && exit 1"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/toptal/davinci/issues"
30
+ },
31
+ "dependencies": {
32
+ "@babel/core": "^7.14.8",
33
+ "@babel/preset-env": "^7.16.4",
34
+ "@babel/preset-react": "^7.10.4",
35
+ "@babel/preset-typescript": "^7.10.4",
36
+ "@cypress/code-coverage": "^3.9.12",
37
+ "@cypress/webpack-preprocessor": "^5.7.0",
38
+ "@testing-library/jest-dom": "^5.14.1",
39
+ "@testing-library/react": "^12.1.2",
40
+ "@toptal/davinci-cli-shared": "1.5.1",
41
+ "@types/jest": "^27.0.3",
42
+ "babel-jest": "^26.3.0",
43
+ "cypress": "^9.4.1",
44
+ "fs-extra": "^10.0.0",
45
+ "glob": "^7.2.0",
46
+ "jest": "^26.6.3",
47
+ "jest-html-reporters": "^2.1.6",
48
+ "jest-junit": "^13.0.0",
49
+ "jest-silent-reporter": "^0.5.0",
50
+ "jest-styled-components": "^7.0.3",
51
+ "jsdom": "^16.5.2",
52
+ "matchmedia-polyfill": "^0.3.2",
53
+ "semver": "^7.3.2"
54
+ }
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-qa",
3
- "version": "5.5.1-alpha-fix-integration-tests-jenkins.6+8ba2e836",
3
+ "version": "5.6.0",
4
4
  "description": "QA package to test your application",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -37,7 +37,7 @@
37
37
  "@cypress/webpack-preprocessor": "^5.7.0",
38
38
  "@testing-library/jest-dom": "^5.14.1",
39
39
  "@testing-library/react": "^12.1.2",
40
- "@toptal/davinci-cli-shared": "1.5.2-alpha-fix-integration-tests-jenkins.8+8ba2e836",
40
+ "@toptal/davinci-cli-shared": "1.5.1",
41
41
  "@types/jest": "^27.0.3",
42
42
  "babel-jest": "^26.3.0",
43
43
  "cypress": "^9.4.1",
@@ -51,6 +51,5 @@
51
51
  "jsdom": "^16.5.2",
52
52
  "matchmedia-polyfill": "^0.3.2",
53
53
  "semver": "^7.3.2"
54
- },
55
- "gitHead": "8ba2e83627d7d4aa0615c59cf1a694777d4e9047"
54
+ }
56
55
  }
@@ -0,0 +1,65 @@
1
+ const convertToCLIParametersMock = jest.fn()
2
+ const getPackageFilePathMock = jest.fn()
3
+
4
+ jest.mock('@toptal/davinci-cli-shared', () => ({
5
+ runSync: jest.fn(),
6
+ print: {
7
+ green: jest.fn()
8
+ },
9
+ convertToCLIParameters: convertToCLIParametersMock,
10
+ files: {
11
+ getPackageFilePath: getPackageFilePathMock
12
+ }
13
+ }))
14
+
15
+ const { runSync } = require('@toptal/davinci-cli-shared')
16
+
17
+ const { action } = require('./end-to-end-tests')
18
+
19
+ describe('endToEndTestCommand', () => {
20
+ it('runs cypress with default options', () => {
21
+ convertToCLIParametersMock.mockReturnValueOnce([])
22
+ getPackageFilePathMock.mockReturnValueOnce('packages/qa/src/configs/cypress.config.json')
23
+
24
+ action({ options: {} })
25
+
26
+ expect(runSync).toHaveBeenCalledWith('yarn', [
27
+ 'cypress',
28
+ 'run',
29
+ '--config-file',
30
+ 'packages/qa/src/configs/cypress.config.json'
31
+ ])
32
+
33
+ expect(convertToCLIParametersMock).toHaveBeenCalledWith({})
34
+ expect(getPackageFilePathMock).toHaveBeenCalledWith(
35
+ '@toptal/davinci-qa',
36
+ 'src/configs/cypress.config.json'
37
+ )
38
+ })
39
+
40
+ it('runs cypress with custom options', () => {
41
+ const spec = 'cypress/integration/activation_flow.spec.ts'
42
+
43
+ convertToCLIParametersMock.mockReturnValueOnce(['--spec', spec])
44
+ getPackageFilePathMock.mockReturnValueOnce('packages/qa/src/configs/cypress.config.json')
45
+
46
+ action({ options: { spec } })
47
+
48
+ expect(runSync).toHaveBeenCalledWith('yarn', [
49
+ 'cypress',
50
+ 'run',
51
+ '--config-file',
52
+ 'packages/qa/src/configs/cypress.config.json',
53
+ '--spec',
54
+ spec
55
+ ])
56
+
57
+ expect(convertToCLIParametersMock).toHaveBeenCalledWith({
58
+ spec
59
+ })
60
+ expect(getPackageFilePathMock).toHaveBeenCalledWith(
61
+ '@toptal/davinci-qa',
62
+ 'src/configs/cypress.config.json'
63
+ )
64
+ })
65
+ })
@@ -55,7 +55,9 @@ const unitTestsCommand = ({
55
55
  }
56
56
 
57
57
  if (isCi) {
58
- const isConfigFileHasCollectCoverageFrom = jestOptions.config && files.getProjectRootFileContent(jestOptions.config).collectCoverageFrom
58
+ const hasCustomConfig = Boolean(jestOptions.config)
59
+ const jestProjectConfig = hasCustomConfig && files.getProjectRootFileContent(jestOptions.config)
60
+ const isConfigFileHasCollectCoverageFrom = hasCustomConfig && jestProjectConfig.collectCoverageFrom
59
61
 
60
62
  defaultOptions.coverage = true
61
63
  defaultOptions.coverageDirectory = 'coverage'
@@ -70,8 +72,12 @@ const unitTestsCommand = ({
70
72
 
71
73
  // to show smaller log of tests running on CI
72
74
  // and a nicer html report
75
+ // Override order: CLI options -> reporters on jest.config -> Davinci defaults
73
76
  if (jestOptions.reporters) {
74
77
  defaultOptions.reporters = jestOptions.reporters
78
+ }
79
+ else if (jestProjectConfig?.reporters) {
80
+ defaultOptions.reporters = jestProjectConfig.reporters
75
81
  } else {
76
82
  defaultOptions.testLocationInResults = true // allows reporters to return test line number
77
83
  defaultOptions.reporters = defaultCIJestReporters(anvilTag)
@@ -0,0 +1,164 @@
1
+ const jestRunCLIMock =jest.fn().mockResolvedValue({ results: {success: true}})
2
+ const getPackageFilePathMock = jest.fn()
3
+ const getProjectRootFilePathMock = jest.fn()
4
+ const getProjectRootFileContentMock = jest.fn().mockReturnValue({
5
+ devDependencies: {}, dependencies: {},
6
+ })
7
+
8
+ jest.mock('@toptal/davinci-cli-shared', () => ({
9
+ runSync: jest.fn(),
10
+ print: {
11
+ green: jest.fn(),
12
+ grey: jest.fn(),
13
+ red: jest.fn(),
14
+ },
15
+ files: {
16
+ getPackageFilePath: getPackageFilePathMock,
17
+ getProjectRootFileContent: getProjectRootFileContentMock,
18
+ getProjectRootFilePath: getProjectRootFilePathMock
19
+ }
20
+ }))
21
+
22
+ jest.mock('jest', () => ({
23
+ runCLI: jestRunCLIMock
24
+ }))
25
+
26
+ const { action } = require('./unit-tests')
27
+ const originalEnv = process.env
28
+
29
+ beforeEach(() => {
30
+ jest.clearAllMocks()
31
+ })
32
+
33
+ afterEach(() => {
34
+ process.env = originalEnv
35
+ })
36
+
37
+ describe('unitTestsCommand', () => {
38
+ describe('when running locally', () => {
39
+ beforeEach(() => {
40
+ delete process.env.CI
41
+ })
42
+
43
+ it('calls the jest CLI without additional reporters', async () => {
44
+ const davinciJestConfigPath = 'packages/qa/src/configs/jest.config.js'
45
+ getPackageFilePathMock.mockReturnValueOnce(davinciJestConfigPath)
46
+
47
+ await action({})
48
+
49
+ expect(jestRunCLIMock).toBeCalledWith(
50
+ {"config": davinciJestConfigPath, "testPathPattern": []},
51
+ expect.anything()
52
+ )
53
+ })
54
+
55
+ })
56
+
57
+ describe('when running on CI', () => {
58
+ beforeEach(() => {
59
+ process.env.CI = true
60
+ })
61
+
62
+ it('calls the jest CLI with default Davinci reporters', async () => {
63
+ const davinciJestConfigPath = 'packages/qa/src/configs/jest.config.js'
64
+ getPackageFilePathMock.mockReturnValueOnce(davinciJestConfigPath)
65
+
66
+ await action({})
67
+
68
+ expect(jestRunCLIMock).toBeCalledWith(
69
+ expect.objectContaining({
70
+ reporters: [
71
+ [
72
+ "jest-silent-reporter",
73
+ {
74
+ useDots: true,
75
+ showPaths: true,
76
+ showWarnings: true,
77
+ },
78
+ ],
79
+ [
80
+ "jest-junit",
81
+ {
82
+ outputDirectory: "reports",
83
+ },
84
+ ],
85
+ [
86
+ "jest-html-reporters",
87
+ {
88
+ publicPath: "./reports",
89
+ },
90
+ ],
91
+ [
92
+ expect.stringContaining("davinci/packages/qa/src/reporters/jest-anvil-reporter.js"),
93
+ {
94
+ anvilTag: undefined,
95
+ },
96
+ ],
97
+ ],
98
+ }),
99
+ expect.anything()
100
+ )
101
+ })
102
+
103
+ it('allows overriding of the default Davinci reporters via custom configuration', async () => {
104
+ const davinciJestConfigPath = 'packages/qa/src/configs/jest.config.js'
105
+ getPackageFilePathMock.mockReturnValueOnce(davinciJestConfigPath)
106
+ const customCLIReporter = 'My-CLI-Reporter'
107
+
108
+ await action({
109
+ options: {
110
+ anvilTag: 'MyTag',
111
+ reporters: customCLIReporter
112
+ }
113
+ })
114
+
115
+ expect(jestRunCLIMock).toBeCalledWith(
116
+ expect.objectContaining({
117
+ reporters: [customCLIReporter],
118
+ }),
119
+ expect.anything()
120
+ )
121
+ })
122
+
123
+ it('allows overriding the default Davinci reporters via custom jest config', async () => {
124
+ const davinciJestConfigPath = 'packages/qa/src/configs/jest.config.js'
125
+ getPackageFilePathMock.mockReturnValueOnce(davinciJestConfigPath)
126
+ const customJestConfigReporter = 'My-Jest-Config-Reporter'
127
+
128
+ getProjectRootFileContentMock.mockReturnValue({reporters: customJestConfigReporter})
129
+
130
+ await action({ options: { config: {}}})
131
+
132
+ expect(jestRunCLIMock).toBeCalledWith(
133
+ expect.objectContaining({
134
+ reporters: [customJestConfigReporter],
135
+ }),
136
+ expect.anything()
137
+ )
138
+ })
139
+
140
+ it('prioritizes the CLI reporters over the custom jest config or the default Davinci reporters', async () => {
141
+ const davinciJestConfigPath = 'packages/qa/src/configs/jest.config.js'
142
+ getPackageFilePathMock.mockReturnValueOnce(davinciJestConfigPath)
143
+ const customCLIReporter = 'My-CLI-Reporter'
144
+ const customJestConfigReporter = 'My-Jest-Config-Reporter'
145
+
146
+ getProjectRootFileContentMock.mockReturnValue({ reporters: customJestConfigReporter })
147
+
148
+ await action({
149
+ options: {
150
+ anvilTag: 'MyTag',
151
+ reporters: customCLIReporter,
152
+ config: {}
153
+ }
154
+ })
155
+
156
+ expect(jestRunCLIMock).toBeCalledWith(
157
+ expect.objectContaining({
158
+ reporters: [customCLIReporter],
159
+ }),
160
+ expect.anything()
161
+ )
162
+ })
163
+ })
164
+ })
@@ -0,0 +1,123 @@
1
+ const JestAnvilReporter = require('./jest-anvil-reporter.js')
2
+ const fs = require('fs')
3
+ const { passedTestResults, failedTestResults, skippedTestResults, combinedTestResults } = require('./test-result-mocks')
4
+
5
+ describe('Jest Anvil reporter', () => {
6
+ const expectedPassedTestResults = {
7
+ test_results: [
8
+ [
9
+ {
10
+
11
+ file_name: "/davinci/packages/qa/src/reporters/jest-anvil-reporter-mocker.test.js",
12
+ line_number: 2,
13
+ status: "passed",
14
+ duration: 3,
15
+ scenario_name: "Example test suite/1 + 1 returns 2",
16
+ description: "1 + 1 returns 2",
17
+ error: null,
18
+ backtrace: null,
19
+ test_type: "unit",
20
+ tag: "platform"
21
+ }
22
+ ]
23
+ ]
24
+ }
25
+
26
+ const expectedFailedTestResults = {
27
+ test_results: [
28
+ [
29
+ {
30
+ file_name: "/davinci/packages/qa/src/reporters/jest-anvil-reporter-mocker.test.js",
31
+ line_number: 2,
32
+ status: "failed",
33
+ duration: 6,
34
+ scenario_name: "Example test suite/1 + 1 returns 3",
35
+ description: "1 + 1 returns 3",
36
+ error: "Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m3\u001b[39m\nReceived: \u001b[31m2\u001b[39m",
37
+ backtrace: "Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m3\u001b[39m\nReceived: \u001b[31m2\u001b[39m\n at Object.<anonymous> (/davinci/packages/qa/src/reporters/jest-anvil-reporter-mocker.test.js:3:17)\n at Object.asyncJestTest (/davinci/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:106:37)\n at /davinci/node_modules/jest-jasmine2/build/queueRunner.js:45:12\n at new Promise (<anonymous>)\n at mapper (/davinci/node_modules/jest-jasmine2/build/queueRunner.js:28:19)\n at /davinci/node_modules/jest-jasmine2/build/queueRunner.js:75:41",
38
+ test_type: "unit",
39
+ tag: "platform"
40
+ }
41
+ ]
42
+ ]
43
+ }
44
+
45
+ const expectedSkippedTestResults = {
46
+ test_results: [
47
+ [
48
+ {
49
+ file_name: "/davinci/packages/qa/src/reporters/jest-anvil-reporter-mocker.test.js",
50
+ line_number: 2,
51
+ status: "pending",
52
+ duration: 0,
53
+ scenario_name: "Example test suite/1 + 1 returns 2",
54
+ description: "1 + 1 returns 2",
55
+ error: null,
56
+ backtrace: null,
57
+ test_type: "unit",
58
+ tag: "platform"
59
+ }
60
+ ]
61
+ ]
62
+ }
63
+
64
+ const expectedCombinedTestResults = {
65
+ test_results: [
66
+ [
67
+ {
68
+ file_name: "/davinci/packages/qa/src/reporters/jest-anvil-reporter-mocker.test.js",
69
+ line_number: 2,
70
+ status: "passed",
71
+ duration: 5,
72
+ scenario_name: "Example test suite/1 + 1 returns 2 (passed)",
73
+ description: "1 + 1 returns 2 (passed)",
74
+ error: null,
75
+ backtrace: null,
76
+ test_type: "unit",
77
+ tag: "platform"
78
+ },
79
+ {
80
+ file_name: "/davinci/packages/qa/src/reporters/jest-anvil-reporter-mocker.test.js",
81
+ line_number: 6,
82
+ status: "failed",
83
+ duration: 7,
84
+ scenario_name: "Example test suite/1 + 1 returns 3 (failed)",
85
+ description: "1 + 1 returns 3 (failed)",
86
+ error: "Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m3\u001b[39m\nReceived: \u001b[31m2\u001b[39m",
87
+ backtrace: "Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m3\u001b[39m\nReceived: \u001b[31m2\u001b[39m\n at Object.<anonymous> (/davinci/packages/qa/src/reporters/jest-anvil-reporter-mocker.test.js:7:17)\n at Object.asyncJestTest (/davinci/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:106:37)\n at /davinci/node_modules/jest-jasmine2/build/queueRunner.js:45:12\n at new Promise (<anonymous>)\n at mapper (/davinci/node_modules/jest-jasmine2/build/queueRunner.js:28:19)\n at /davinci/node_modules/jest-jasmine2/build/queueRunner.js:75:41",
88
+ test_type: "unit",
89
+ tag: "platform"
90
+ },
91
+ {
92
+ file_name: "/davinci/packages/qa/src/reporters/jest-anvil-reporter-mocker.test.js",
93
+ line_number: 10,
94
+ status: "pending",
95
+ duration: 0,
96
+ scenario_name: "Example test suite/1 + 1 returns 2 (skipped)",
97
+ description: "1 + 1 returns 2 (skipped)",
98
+ error: null,
99
+ backtrace: null,
100
+ test_type: "unit",
101
+ tag: "platform"
102
+ }
103
+ ]
104
+ ]
105
+ }
106
+
107
+ beforeEach(() => {
108
+ jest.clearAllMocks();
109
+ });
110
+
111
+ test.each`
112
+ input | expectedOutput | testType
113
+ ${passedTestResults} | ${expectedPassedTestResults} | ${"passing tests"}
114
+ ${failedTestResults} | ${expectedFailedTestResults} | ${"failing tests"}
115
+ ${skippedTestResults} | ${expectedSkippedTestResults} | ${"skipped tests"}
116
+ ${combinedTestResults} | ${expectedCombinedTestResults} | ${"a combination of test results"}
117
+ `('returns a payload matching Anvil for $testType', ({ input, expectedOutput, testType }) => {
118
+ const spy = jest.spyOn(fs, 'writeFileSync')
119
+ const jestAnvilReporter = new JestAnvilReporter(undefined, { anvilTag: 'platform' })
120
+ jestAnvilReporter.onRunComplete(undefined, input)
121
+ expect(spy).toBeCalledWith("./anvil_test_results.json", JSON.stringify(expectedOutput, undefined, 2), expect.anything())
122
+ })
123
+ })
@@ -0,0 +1,59 @@
1
+ const getPackageFileContentMock = jest.fn()
2
+
3
+ jest.mock('@toptal/davinci-cli-shared', () => ({
4
+ files: {
5
+ getPackageFileContent: getPackageFileContentMock
6
+ }
7
+ }))
8
+
9
+ const jestArgsToCLIRules = require('./jest-args-to-cli-converters')
10
+
11
+ describe('jestArgsToCLIRules "reporters"', () => {
12
+ const reportersRule = jestArgsToCLIRules['reporters']
13
+
14
+ it('converts correctly arrays', () => {
15
+ expect(
16
+ reportersRule(['reporter1', 'reporter2'])
17
+ ).toEqual(['reporter1', 'reporter2'])
18
+ })
19
+
20
+ it('converts correctly string', () => {
21
+ expect(
22
+ reportersRule('reporter1')
23
+ ).toEqual(['reporter1'])
24
+ })
25
+ })
26
+
27
+ describe('jestArgsToCLIRules "setupFilesAfterEnv"', () => {
28
+ const setupFilesAfterEnvRule = jestArgsToCLIRules['setupFilesAfterEnv']
29
+
30
+ it('takes default values from the davinci jest.config.js file', () => {
31
+ getPackageFileContentMock.mockReturnValueOnce({
32
+ setupFilesAfterEnv: ['davinci-setup-files']
33
+ })
34
+
35
+ expect(
36
+ setupFilesAfterEnvRule()
37
+ ).toEqual(['davinci-setup-files'])
38
+ })
39
+
40
+ it('merges default values with passed setup files', () => {
41
+ getPackageFileContentMock.mockReturnValueOnce({
42
+ setupFilesAfterEnv: ['davinci-setup-files']
43
+ })
44
+
45
+ expect(
46
+ setupFilesAfterEnvRule(['file1', 'file2'])
47
+ ).toEqual(['davinci-setup-files', 'file1', 'file2'])
48
+ })
49
+
50
+ it('merges default values with single passed setup file', () => {
51
+ getPackageFileContentMock.mockReturnValueOnce({
52
+ setupFilesAfterEnv: ['davinci-setup-files']
53
+ })
54
+
55
+ expect(
56
+ setupFilesAfterEnvRule('file1')
57
+ ).toEqual(['davinci-setup-files', 'file1'])
58
+ })
59
+ })
@@ -0,0 +1,78 @@
1
+ const styledComponentsVersionCheck = require('./styled-components-version-check')
2
+
3
+ const successTest = (styledComponentsVersion, dependenciesKeys) => {
4
+ const packageJson = {}
5
+
6
+ dependenciesKeys.forEach(dependenciesKey => {
7
+ packageJson[dependenciesKey] = {
8
+ 'styled-components': styledComponentsVersion
9
+ }
10
+ })
11
+
12
+ let error = null
13
+ try {
14
+ styledComponentsVersionCheck(packageJson)
15
+ } catch (e) {
16
+ error = e
17
+ }
18
+
19
+ expect(error).toBeNull()
20
+ }
21
+
22
+ const errorTest = (styledComponentsVersion, dependenciesKeys) => {
23
+ const packageJson = {}
24
+
25
+ dependenciesKeys.forEach(dependenciesKey => {
26
+ packageJson[dependenciesKey] = {
27
+ 'styled-components': styledComponentsVersion
28
+ }
29
+ })
30
+
31
+ let error = null
32
+ try {
33
+ styledComponentsVersionCheck(packageJson)
34
+ } catch (e) {
35
+ error = e
36
+ }
37
+
38
+ expect(error).not.toBeNull()
39
+ expect(error.message).toContain(styledComponentsVersion)
40
+ }
41
+
42
+ describe('styled-components version check', () => {
43
+ describe('has wrong (^4.4.1) SC version in dependencies', () => {
44
+ test('should throw an error', () => {
45
+ errorTest('^4.4.1', ['dependencies'])
46
+ })
47
+ })
48
+
49
+ describe('has correct (^5.0.1) SC version in dependencies', () => {
50
+ test('should NOT throw an error', () => {
51
+ successTest('^5.0.1', ['dependencies'])
52
+ })
53
+ })
54
+
55
+ describe('has wrong (^4.4.1) SC version in devDependencies and peerDependencies', () => {
56
+ test('should throw an error', () => {
57
+ errorTest('^4.4.1', ['devDependencies', 'peerDependencies'])
58
+ })
59
+ })
60
+
61
+ describe('has correct (^5.0.1) SC version in devDependencies and peerDependencies', () => {
62
+ test('should NOT throw an error', () => {
63
+ successTest('^5.0.1', ['devDependencies', 'peerDependencies'])
64
+ })
65
+ })
66
+
67
+ describe('has wrong (^4.4.1) SC version in devDependencies', () => {
68
+ test('should throw an error', () => {
69
+ errorTest('^4.4.1', ['devDependencies'])
70
+ })
71
+ })
72
+
73
+ describe('has correct (^5.0.1) SC version in devDependencies', () => {
74
+ test('should NOT throw an error', () => {
75
+ successTest('^5.0.1', ['devDependencies'])
76
+ })
77
+ })
78
+ })
@@ -0,0 +1,32 @@
1
+ const toJestCLIArguments = require('./to-jest-cli-arguments')
2
+
3
+ const EXAMPLE_REPORTER = 'some-jest-reporter'
4
+ const ARGS_TO_CLI_RESULT = [EXAMPLE_REPORTER]
5
+
6
+ jest.mock('./jest-args-to-cli-converters.js', () => ({
7
+ 'reporters': () => ARGS_TO_CLI_RESULT
8
+ }))
9
+
10
+ describe('toJestCLIArguments', () => {
11
+ it('converts boolean strings to booleans correctly', () => {
12
+ expect(
13
+ toJestCLIArguments({
14
+ cache: 'false',
15
+ ci: 'true'
16
+ })
17
+ ).toEqual({
18
+ cache: false,
19
+ ci: true
20
+ })
21
+ })
22
+
23
+ it('converts some rules by using args-to-cli rules', () => {
24
+ expect(
25
+ toJestCLIArguments({
26
+ 'reporters': EXAMPLE_REPORTER
27
+ })
28
+ ).toEqual({
29
+ 'reporters': ARGS_TO_CLI_RESULT
30
+ })
31
+ })
32
+ })