Skip to content

Commit

Permalink
chore: remove extra spacing on some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nklayman committed May 31, 2020
1 parent 2b3aebd commit 2642529
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 128 deletions.
30 changes: 15 additions & 15 deletions __tests__/build.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const portfinder = require('portfinder')
const checkLogs = require('./checkLogs.helper.js')

portfinder.basePort = 9515
const runTests = async useTS => {
const runTests = async (useTS) => {
const { project, projectName } = await create('build', useTS)

const isWin = process.platform === 'win32'
const projectPath = p =>
const projectPath = (p) =>
path.join(process.cwd(), '__tests__/projects/' + projectName, p)

await project.run('vue-cli-service electron:build --x64 --dir')
// Ensure /dist is not modified
// Ensure /dist is not modified
expect(project.has('dist')).toBe(false)
// Ensure build successfully outputted files
// Ensure build successfully outputted files
expect(project.has('dist_electron/bundled/index.html')).toBe(true)
expect(project.has('dist_electron/bundled/favicon.ico')).toBe(true)
expect(project.has('dist_electron/bundled/js')).toBe(true)
Expand All @@ -30,7 +30,7 @@ const runTests = async useTS => {
true
)
}
// Ensure that setup files were not created
// Ensure that setup files were not created
expect(project.has(`dist_electron/${projectName} Setup 0.1.0.exe`)).toBe(
false
)
Expand All @@ -41,9 +41,9 @@ const runTests = async useTS => {
// Launch app with spectron
const app = new Application({
path: `./__tests__/projects/${projectName}/dist_electron/${
isWin ? 'win' : 'linux'
}-unpacked/${projectName}${isWin ? '.exe' : ''}`,
// Make sure tests do not interfere with each other
isWin ? 'win' : 'linux'
}-unpacked/${projectName}${isWin ? '.exe' : ''}`,
// Make sure tests do not interfere with each other
port: await portfinder.getPortPromise(),
// Increase wait timeout for parallel testing
waitTimeout: 10000
Expand All @@ -56,24 +56,24 @@ const runTests = async useTS => {
// Check that proper info was logged
await checkLogs({ client, projectName, projectPath, mode: 'build' })

// Window was created
// Window was created
expect(await client.getWindowCount()).toBe(1)
// It is not minimized
// It is not minimized
expect(await win.isMinimized()).toBe(false)
// Dev tools is not open
// Dev tools is not open
expect(await win.isDevToolsOpened()).toBe(false)
// Window is visible
// Window is visible
expect(await win.isVisible()).toBe(true)
// Size is correct
// Size is correct
const { width, height } = await win.getBounds()
expect(width).toBeGreaterThan(0)
expect(height).toBeGreaterThan(0)
// Load was successful
expect(await app.webContents.isLoading()).toBe(false)
// App is loaded properly
// App is loaded properly
expect(
(await client.getHTML('#app')).indexOf(
`Welcome to Your Vue.js ${useTS ? '+ TypeScript ' : ''}App`
`Welcome to Your Vue.js ${useTS ? '+ TypeScript ' : ''}App`
)
).not.toBe(-1)

Expand Down
38 changes: 19 additions & 19 deletions __tests__/checkLogs.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ module.exports = async ({ client, projectPath, projectName, mode }) => {
`dist_electron/${isWin ? 'win' : 'linux'}-unpacked/resources/app.asar`
)

await client.getRenderProcessLogs().then(logs => {
logs.forEach(log => {
// Make sure there are no fatal errors
await client.getRenderProcessLogs().then((logs) => {
logs.forEach((log) => {
// Make sure there are no fatal errors
expect(log.level).not.toBe('SEVERE')
})
let appBaseUrl = logs
// Find BASE_URL log
.find(v => v.message.indexOf('process.env.BASE_URL=') !== -1)
// Find BASE_URL log
.find((v) => v.message.indexOf('process.env.BASE_URL=') !== -1)
// Get just the value
.message.split('=')[1]
// Remove any quotes
appBaseUrl = appBaseUrl.replace('"', '')
// Base url should be root of server or packaged asar
// Base url should be root of server or packaged asar
expect(path.normalize(appBaseUrl)).toBe(
isBuild ? outputPath : path.sep /* Server root */
)

let appStatic = logs
// Find __static log
.find(v => v.message.indexOf('__static=') !== -1)
// Find __static log
.find((v) => v.message.indexOf('__static=') !== -1)
// Get just the value
.message.split('=')[1]
// Remove any quotes
appStatic = appStatic.replace('"', '')
// __static should point to public folder or packaged asar
// __static should point to public folder or packaged asar
expect(path.normalize(appStatic)).toBe(
isBuild ? outputPath : projectPath('public')
)

let vuePath = logs
// Find vuePath log
.find(v => v.message.indexOf('vuePath=') !== -1)
// Find vuePath log
.find((v) => v.message.indexOf('vuePath=') !== -1)
// Get just the value
.message.split('=')[1]
// Remove any quotes
Expand All @@ -51,8 +51,8 @@ module.exports = async ({ client, projectPath, projectName, mode }) => {
}

let mockExternalPath = logs
// Find externalModulePath log
.find(v => v.message.indexOf('mockExternalPath=') !== -1)
// Find externalModulePath log
.find((v) => v.message.indexOf('mockExternalPath=') !== -1)
// Get just the value
.message.split('=')[1]
// Remove any quotes
Expand All @@ -63,22 +63,22 @@ module.exports = async ({ client, projectPath, projectName, mode }) => {
}
})

await client.getMainProcessLogs().then(logs => {
await client.getMainProcessLogs().then((logs) => {
let appStatic = logs
// Find __static log
.find(m => m.indexOf('__static=') !== -1)
// Find __static log
.find((m) => m.indexOf('__static=') !== -1)
// Get just the value
.split('=')[1]
// Remove any quotes
appStatic = appStatic.replace('"', '').split(',')[0]
// __static should point to public folder or packaged asar
// __static should point to public folder or packaged asar
expect(path.normalize(appStatic)).toBe(
isBuild ? outputPath : projectPath('public')
)

let mockExternalPath = logs
// Find externalModulePath log
.find(v => v.indexOf('mockExternalPath=') !== -1)
// Find externalModulePath log
.find((v) => v.indexOf('mockExternalPath=') !== -1)
// Get just the value
.split('=')[1]
// Remove any quotes
Expand Down
63 changes: 36 additions & 27 deletions __tests__/commands.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ console.log = jest.fn()
beforeEach(() => {
jest.clearAllMocks()
})
chokidar.watch.mockImplementation(file => {
chokidar.watch.mockImplementation((file) => {
return {
on: (type, cb) => {}
}
Expand All @@ -84,14 +84,14 @@ const runCommand = async (command, options = {}, args = {}, rawArgs = []) => {
if (!args._) args._ = []
const commands = {}
const api = {
// Make app think typescript plugin is installed
// Make app think typescript plugin is installed
hasPlugin: jest.fn().mockReturnValue(true),
registerCommand: jest.fn().mockImplementation((name, options, command) => {
// Save registered commands
commands[name] = command
}),
// So we can ensure that files were resolved properly
resolve: jest.fn(path => 'projectPath/' + path),
resolve: jest.fn((path) => 'projectPath/' + path),
chainWebpack: jest.fn(),
service: {
// Mock api.service.run('build/serve')
Expand Down Expand Up @@ -120,13 +120,13 @@ describe('electron:build', () => {
})

const mainConfig = webpack.mock.calls[0][0]
// Typescript rule is not added
// Typescript rule is not added
expect(Object.keys(mainConfig)).not.toContain('module')
// Ts files are not resolved
// Ts files are not resolved
expect(
mainConfig.resolve.extensions ? mainConfig.resolve.extensions : []
).not.toContain('ts')
// Proper entry file is used
// Proper entry file is used
expect(mainConfig.entry.background[0]).toBe('projectPath/src/background.js')
})

Expand All @@ -140,7 +140,7 @@ describe('electron:build', () => {
})

const mainConfig = webpack.mock.calls[0][0]
// Proper entry file is used
// Proper entry file is used
expect(mainConfig.entry.background[0]).toBe(
'projectPath/customBackground.js'
)
Expand All @@ -156,11 +156,11 @@ describe('electron:build', () => {
})

const mainConfig = webpack.mock.calls[0][0]
// Main config output is correct
// Main config output is correct
expect(mainConfig.output.path).toBe('projectPath/output/bundled')
// cli-service build output is correct
expect(serviceRun.mock.calls[0][1].dest).toBe(`output${path.sep}bundled`)
// Electron-builder output is correct
// Electron-builder output is correct
expect(builder.build.mock.calls[0][0].config.directories.output).toBe(
'output'
)
Expand All @@ -170,11 +170,11 @@ describe('electron:build', () => {
await runCommand('electron:build', {}, { dest: 'output' })

const mainConfig = webpack.mock.calls[0][0]
// Main config output is correct
// Main config output is correct
expect(mainConfig.output.path).toBe('projectPath/output/bundled')
// cli-service build output is correct
expect(serviceRun.mock.calls[0][1].dest).toBe(`output${path.sep}bundled`)
// Electron-builder output is correct
// Electron-builder output is correct
expect(builder.build.mock.calls[0][0].config.directories.output).toBe(
'output'
)
Expand All @@ -184,7 +184,7 @@ describe('electron:build', () => {
await runCommand('electron:build', {
pluginOptions: {
electronBuilder: {
chainWebpackMainProcess: config => {
chainWebpackMainProcess: (config) => {
config.node.set('shouldBe', 'expected')
return config
}
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('electron:build', () => {

test.each(['report', 'report-json'])(
'--%s arg is passed to renderer build',
async argName => {
async (argName) => {
const args = {}
args[argName] = true
await runCommand('electron:build', {}, args)
Expand Down Expand Up @@ -339,7 +339,7 @@ describe('electron:build', () => {

test.each(['string config', 'object config'])(
'Adds mock legacy assets file for each page (%s)',
async configType => {
async (configType) => {
const stringConfig = configType === 'string config'
await runCommand('electron:build', {
pages: {
Expand Down Expand Up @@ -408,7 +408,9 @@ describe('electron:build', () => {
expect(webpack).toBeCalledTimes(2)
const preloadWebpackCall = webpack.mock.calls[1][0]
expect(preloadWebpackCall.target).toBe('electron-preload')
expect(preloadWebpackCall.entry).toEqual({ preload: ['projectPath/preloadFile'] })
expect(preloadWebpackCall.entry).toEqual({
preload: ['projectPath/preloadFile']
})
// Make sure preload bundle has been run
expect(mockRun).toHaveBeenCalledTimes(2)
webpack.mockClear()
Expand Down Expand Up @@ -454,13 +456,13 @@ describe('electron:serve', () => {
})

const mainConfig = webpack.mock.calls[0][0]
// Typescript rule is not added
// Typescript rule is not added
expect(Object.keys(mainConfig)).not.toContain('module')
// Ts files are not resolved
// Ts files are not resolved
expect(
mainConfig.resolve.extensions ? mainConfig.resolve.extensions : []
).not.toContain('ts')
// Proper entry file is used
// Proper entry file is used
expect(mainConfig.entry.index[0]).toBe('projectPath/src/background.js')
})

Expand All @@ -474,7 +476,7 @@ describe('electron:serve', () => {
})

const mainConfig = webpack.mock.calls[0][0]
// Proper entry file is used
// Proper entry file is used
expect(mainConfig.entry.index[0]).toBe('projectPath/customBackground.js')
})

Expand All @@ -488,15 +490,15 @@ describe('electron:serve', () => {
})

const mainConfig = webpack.mock.calls[0][0]
// Main config output is correct
// Main config output is correct
expect(mainConfig.output.path).toBe('projectPath/output')
})

test('Custom main process webpack config is used if provided', async () => {
await runCommand('electron:serve', {
pluginOptions: {
electronBuilder: {
chainWebpackMainProcess: config => {
chainWebpackMainProcess: (config) => {
config.node.set('shouldBe', 'expected')
return config
}
Expand Down Expand Up @@ -565,7 +567,7 @@ describe('electron:serve', () => {
// UglifyJS plugin does not exist
expect(
mainConfig.plugins.find(
p => p.__pluginConstructorName === 'UglifyJsPlugin'
(p) => p.__pluginConstructorName === 'UglifyJsPlugin'
)
).toBeUndefined()
// Source maps are enabled
Expand Down Expand Up @@ -604,7 +606,9 @@ describe('electron:serve', () => {
})

// Proper file is watched
expect(chokidar.watch.mock.calls[0][0]).toEqual(['projectPath/customBackground'])
expect(chokidar.watch.mock.calls[0][0]).toEqual([
'projectPath/customBackground'
])
// Child has not yet been killed or unwatched
expect(mockExeca.send).not.toBeCalled()
expect(mockExeca.kill).not.toBeCalled()
Expand Down Expand Up @@ -643,10 +647,10 @@ describe('electron:serve', () => {
// So we can make sure it wasn't called
jest.spyOn(process, 'exit')
const watchCb = {}
chokidar.watch.mockImplementation(files => {
chokidar.watch.mockImplementation((files) => {
return {
on: (type, cb) => {
files.forEach(file => {
files.forEach((file) => {
// Set callback to be called later
watchCb[file] = cb
})
Expand All @@ -665,7 +669,10 @@ describe('electron:serve', () => {
})

// Proper file is watched
expect(chokidar.watch.mock.calls[0][0]).toEqual(['projectPath/customBackground', 'projectPath/listFile'])
expect(chokidar.watch.mock.calls[0][0]).toEqual([
'projectPath/customBackground',
'projectPath/listFile'
])
// Child has not yet been killed or unwatched
expect(mockExeca.send).not.toBeCalled()
expect(mockExeca.kill).not.toBeCalled()
Expand Down Expand Up @@ -864,7 +871,9 @@ describe('electron:serve', () => {
expect(webpack).toBeCalledTimes(2)
const preloadWebpackCall = webpack.mock.calls[1][0]
expect(preloadWebpackCall.target).toBe('electron-preload')
expect(preloadWebpackCall.entry).toEqual({ preload: ['projectPath/preloadFile'] })
expect(preloadWebpackCall.entry).toEqual({
preload: ['projectPath/preloadFile']
})
// Make sure preload bundle has been run
expect(mockRun).toHaveBeenCalledTimes(2)
webpack.mockClear()
Expand Down
Loading

0 comments on commit 2642529

Please sign in to comment.