Skip to content

Commit 92918f6

Browse files
committed
Add jest
1 parent 57d8767 commit 92918f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2035
-99
lines changed

.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module.exports = {
22
env: {
33
browser: true,
44
es6: true,
5-
node: true
5+
node: true,
6+
jest: true
67
},
78
extends: ['standard'],
89
globals: {

__mocks__/commander.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function Commander() {
2+
Commander.prototype.version = jest.fn().mockReturnValue(this)
3+
Commander.prototype.usage = jest.fn().mockReturnValue(this)
4+
Commander.prototype.command = jest.fn().mockReturnValue(this)
5+
Commander.prototype.action = jest.fn().mockReturnValue(this)
6+
Commander.prototype.description = jest.fn().mockReturnValue(this)
7+
Commander.prototype.option = jest.fn().mockReturnValue(this)
8+
Commander.prototype.alias = jest.fn().mockReturnValue(this)
9+
Commander.prototype.parse = jest.fn().mockReturnValue(this)
10+
Commander.prototype.outputHelp = jest.fn().mockReturnValue(this)
11+
}
12+
const commander = new Commander()
13+
14+
export default commander

__test__/index.test.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import commander from 'commander'
2+
// import { create, start, clear, pack, test, run } from 'runner'
3+
4+
import { perform } from 'index'
5+
6+
jest.mock('commander')
7+
8+
describe('bozon cli', () => {
9+
beforeEach(() => {
10+
perform()
11+
})
12+
13+
describe('version', () => {
14+
it('sets current version', () => {
15+
expect(commander.version).toHaveBeenCalledWith('0.10.8')
16+
})
17+
18+
it('sets usage instruction', () => {
19+
expect(commander.usage).toHaveBeenCalledWith('[options]')
20+
})
21+
})
22+
23+
describe('new', () => {
24+
it('sets new command', () => {
25+
expect(commander.command).toHaveBeenNthCalledWith(1, 'new <name>')
26+
})
27+
28+
it('adds option to new command', () => {
29+
expect(commander.option).toHaveBeenNthCalledWith(1, '--skip-install')
30+
})
31+
})
32+
33+
describe('start', () => {
34+
it('sets start command', () => {
35+
expect(commander.command).toHaveBeenNthCalledWith(2, 'start')
36+
})
37+
38+
it('add alias', () => {
39+
expect(commander.alias).toHaveBeenNthCalledWith(1, 's')
40+
})
41+
42+
it('adds inspect option to start command', () => {
43+
expect(commander.option).toHaveBeenNthCalledWith(2, '--inspect <port>')
44+
})
45+
46+
it('adds inspect-brk option to start command', () => {
47+
expect(commander.option).toHaveBeenNthCalledWith(
48+
3,
49+
'--inspect-brk <port>'
50+
)
51+
})
52+
})
53+
54+
describe('test', () => {
55+
it('sets test command', () => {
56+
expect(commander.command).toHaveBeenNthCalledWith(3, 'test [spec]')
57+
})
58+
59+
it('adds timeout option to test command', () => {
60+
expect(commander.option).toHaveBeenNthCalledWith(
61+
4,
62+
'--timeout <miliseconds>'
63+
)
64+
})
65+
})
66+
67+
describe('clear', () => {
68+
it('sets clear command', () => {
69+
expect(commander.command).toHaveBeenNthCalledWith(4, 'clear')
70+
})
71+
})
72+
73+
describe('package', () => {
74+
it('sets package command', () => {
75+
expect(commander.command).toHaveBeenNthCalledWith(5, 'package <platform>')
76+
})
77+
78+
it('adds publish option to package command', () => {
79+
expect(commander.option).toHaveBeenNthCalledWith(5, '--publish')
80+
})
81+
})
82+
83+
it('sets descriptions for commands', () => {
84+
expect(commander.description).toHaveBeenCalledTimes(5)
85+
})
86+
87+
it('sets actions for commands', () => {
88+
expect(commander.action).toHaveBeenCalledTimes(5)
89+
})
90+
})

babel.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current'
8+
}
9+
}
10+
]
11+
]
12+
}

bin/bozon

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#! /usr/bin/env node
22

3-
require('../dist/index.js')
3+
require('../dist/index.js').perform()

jest.config.js

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
// All imported modules in your tests should be mocked automatically
6+
// automock: true,
7+
8+
// Stop running tests after `n` failures
9+
// bail: 0,
10+
11+
// Respect "browser" field in package.json when resolving modules
12+
// browser: false,
13+
14+
// The directory where Jest should store its cached dependency information
15+
// cacheDirectory: "/private/var/folders/z_/3ndgqq0n609bqbnfhw41z2fr0000gn/T/jest_dx",
16+
17+
// Automatically clear mock calls and instances between every test
18+
clearMocks: true,
19+
20+
// Indicates whether the coverage information should be collected while executing the test
21+
// collectCoverage: false,
22+
23+
// An array of glob patterns indicating a set of files for which coverage information should be collected
24+
// collectCoverageFrom: undefined,
25+
26+
// The directory where Jest should output its coverage files
27+
// coverageDirectory: undefined,
28+
29+
// An array of regexp pattern strings used to skip coverage collection
30+
// coveragePathIgnorePatterns: [
31+
// "/node_modules/"
32+
// ],
33+
34+
// A list of reporter names that Jest uses when writing coverage reports
35+
// coverageReporters: [
36+
// "json",
37+
// "text",
38+
// "lcov",
39+
// "clover"
40+
// ],
41+
42+
// An object that configures minimum threshold enforcement for coverage results
43+
// coverageThreshold: undefined,
44+
45+
// A path to a custom dependency extractor
46+
// dependencyExtractor: undefined,
47+
48+
// Make calling deprecated APIs throw helpful error messages
49+
// errorOnDeprecated: false,
50+
51+
// Force coverage collection from ignored files using an array of glob patterns
52+
// forceCoverageMatch: [],
53+
54+
// A path to a module which exports an async function that is triggered once before all test suites
55+
// globalSetup: undefined,
56+
57+
// A path to a module which exports an async function that is triggered once after all test suites
58+
// globalTeardown: undefined,
59+
60+
// A set of global variables that need to be available in all test environments
61+
// globals: {},
62+
63+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
64+
// maxWorkers: "50%",
65+
66+
// An array of directory names to be searched recursively up from the requiring module's location
67+
moduleDirectories: [
68+
'node_modules',
69+
'src'
70+
],
71+
72+
// An array of file extensions your modules use
73+
// moduleFileExtensions: [
74+
// "js",
75+
// "json",
76+
// "jsx",
77+
// "ts",
78+
// "tsx",
79+
// "node"
80+
// ],
81+
82+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
83+
// moduleNameMapper: {},
84+
85+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
86+
// modulePathIgnorePatterns: [],
87+
88+
// Activates notifications for test results
89+
// notify: false,
90+
91+
// An enum that specifies notification mode. Requires { notify: true }
92+
// notifyMode: "failure-change",
93+
94+
// A preset that is used as a base for Jest's configuration
95+
// preset: undefined,
96+
97+
// Run tests from one or more projects
98+
// projects: undefined,
99+
100+
// Use this configuration option to add custom reporters to Jest
101+
// reporters: undefined,
102+
103+
// Automatically reset mock state between every test
104+
// resetMocks: false,
105+
106+
// Reset the module registry before running each individual test
107+
// resetModules: false,
108+
109+
// A path to a custom resolver
110+
// resolver: undefined,
111+
112+
// Automatically restore mock state between every test
113+
// restoreMocks: false,
114+
115+
// The root directory that Jest should scan for tests and modules within
116+
// rootDir: undefined,
117+
118+
// A list of paths to directories that Jest should use to search for files in
119+
// roots: [
120+
// "<rootDir>"
121+
// ],
122+
123+
// Allows you to use a custom runner instead of Jest's default test runner
124+
// runner: "jest-runner",
125+
126+
// The paths to modules that run some code to configure or set up the testing environment before each test
127+
// setupFiles: [],
128+
129+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
130+
// setupFilesAfterEnv: [],
131+
132+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
133+
// snapshotSerializers: [],
134+
135+
// The test environment that will be used for testing
136+
testEnvironment: 'node'
137+
138+
// Options that will be passed to the testEnvironment
139+
// testEnvironmentOptions: {},
140+
141+
// Adds a location field to test results
142+
// testLocationInResults: false,
143+
144+
// The glob patterns Jest uses to detect test files
145+
// testMatch: [
146+
// "**/__tests__/**/*.[jt]s?(x)",
147+
// "**/?(*.)+(spec|test).[tj]s?(x)"
148+
// ],
149+
150+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
151+
// testPathIgnorePatterns: [
152+
// "/node_modules/"
153+
// ],
154+
155+
// The regexp pattern or array of patterns that Jest uses to detect test files
156+
// testRegex: [],
157+
158+
// This option allows the use of a custom results processor
159+
// testResultsProcessor: undefined,
160+
161+
// This option allows use of a custom test runner
162+
// testRunner: "jasmine2",
163+
164+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
165+
// testURL: "http://localhost",
166+
167+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
168+
// timers: "real",
169+
170+
// A map from regular expressions to paths to transformers
171+
// transform: undefined,
172+
173+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
174+
// transformIgnorePatterns: [
175+
// "/node_modules/"
176+
// ],
177+
178+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
179+
// unmockedModulePathPatterns: undefined,
180+
181+
// Indicates whether each individual test should be reported during the run
182+
// verbose: undefined,
183+
184+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
185+
// watchPathIgnorePatterns: [],
186+
187+
// Whether to use watchman for file crawling
188+
// watchman: true,
189+
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"scripts": {
1111
"build": "npx webpack",
1212
"lint": "npx eslint src",
13-
"test": "npx mocha test/lib --recursive --require coffeescript/register --extension coffee"
13+
"test": "npx jest",
14+
"test:legacy": "npx mocha test/lib --recursive --require coffeescript/register --extension coffee"
1415
},
1516
"keywords": [
1617
"electron",
@@ -49,6 +50,7 @@
4950
"@babel/core": "^7.9.0",
5051
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
5152
"@babel/preset-env": "^7.9.0",
53+
"babel-jest": "^25.2.0",
5254
"babel-loader": "^8.1.0",
5355
"chai": "^4.2.0",
5456
"coffeescript": "^2.5.1",
@@ -58,6 +60,7 @@
5860
"eslint-plugin-node": "^11.0.0",
5961
"eslint-plugin-promise": "^4.2.1",
6062
"eslint-plugin-standard": "^4.0.1",
63+
"jest": "^25.2.0",
6164
"mocha": "^7.1.1",
6265
"mock-require": "^3.0.3",
6366
"prettier": "2.0.2",

0 commit comments

Comments
 (0)