Merge pull request #18932 from rafeca/add-linting-to-specs

Stop using jasmine test functions from async-spec-helpers.js
This commit is contained in:
Rafael Oleza
2019-03-01 19:26:22 +01:00
committed by GitHub
42 changed files with 34 additions and 470 deletions

View File

@@ -1,5 +1,3 @@
const { it, beforeEach } = require('./helpers/async-spec-helpers')
describe('About', () => {
let workspaceElement

View File

@@ -1,9 +1,4 @@
const {
it,
beforeEach,
afterEach,
conditionPromise
} = require('./helpers/async-spec-helpers')
const { conditionPromise } = require('./helpers/async-spec-helpers')
const MockUpdater = require('./mocks/updater')
describe('the status bar', () => {

View File

@@ -3,35 +3,6 @@
const { now } = Date
const { setTimeout } = global
export function beforeEach (fn) {
global.beforeEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
export function afterEach (fn) {
global.afterEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) {
module.exports[name] = function (description, fn) {
global[name](description, function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
})
export async function conditionPromise (condition) {
const startTime = now()
@@ -53,13 +24,3 @@ export function timeoutPromise (timeout) {
setTimeout(resolve, timeout)
})
}
function waitsForPromise (fn) {
const promise = fn()
global.waitsFor('spec promise to resolve', function (done) {
promise.then(done, function (error) {
jasmine.getEnv().currentSpec.fail(error)
done()
})
})
}

View File

@@ -1,5 +1,4 @@
const { shell } = require('electron')
const { it, beforeEach, afterEach } = require('./helpers/async-spec-helpers')
const main = require('../lib/main')
const AboutView = require('../lib/components/about-view')
const UpdateView = require('../lib/components/update-view')

View File

@@ -1,39 +1,5 @@
/** @babel */
export function beforeEach (fn) {
global.beforeEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
export function afterEach (fn) {
global.afterEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) {
module.exports[name] = function (description, fn) {
if (fn === undefined) {
global[name](description)
return
}
global[name](description, function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
})
export async function conditionPromise (
condition,
description = 'anonymous condition'
@@ -58,49 +24,3 @@ export function timeoutPromise (timeout) {
global.setTimeout(resolve, timeout)
})
}
function waitsForPromise (fn) {
const promise = fn()
global.waitsFor('spec promise to resolve', function (done) {
promise.then(done, function (error) {
jasmine.getEnv().currentSpec.fail(error)
done()
})
})
}
export function emitterEventPromise (emitter, event, timeout = 15000) {
return new Promise((resolve, reject) => {
const timeoutHandle = setTimeout(() => {
reject(new Error(`Timed out waiting for '${event}' event`))
}, timeout)
emitter.once(event, () => {
clearTimeout(timeoutHandle)
resolve()
})
})
}
export function promisify (original) {
return function (...args) {
return new Promise((resolve, reject) => {
args.push((err, ...results) => {
if (err) {
reject(err)
} else {
resolve(...results)
}
})
return original(...args)
})
}
}
export function promisifySome (obj, fnNames) {
const result = {}
for (const fnName of fnNames) {
result[fnName] = promisify(obj[fnName])
}
return result
}

View File

@@ -1,5 +1,3 @@
const { it, fit, ffit, afterEach, beforeEach } = require('./async-spec-helpers') // eslint-disable-line no-unused-vars
describe('Dev Live Reload', () => {
describe('package activation', () => {
let [pack, mainModule] = []

View File

@@ -2,12 +2,7 @@ const path = require('path')
const UIWatcher = require('../lib/ui-watcher')
const {
it,
afterEach,
beforeEach,
conditionPromise
} = require('./async-spec-helpers')
const { conditionPromise } = require('./async-spec-helpers')
describe('UIWatcher', () => {
let uiWatcher = null

View File

@@ -1,41 +0,0 @@
exports.beforeEach = function beforeEach (fn) {
global.beforeEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise('beforeEach promise', result)
}
})
}
exports.afterEach = function afterEach (fn) {
global.afterEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise('afterEach promise', result)
}
})
}
;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) {
exports[name] = function (description, fn) {
if (fn === undefined) {
global[name](description)
return
}
global[name](description, function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise('test promise', result)
}
})
}
})
function waitsForPromise (message, promise) {
global.waitsFor(message, done => {
promise.then(done, error => {
jasmine.getEnv().currentSpec.fail(error)
done()
})
})
}

View File

@@ -1,6 +1,5 @@
const path = require('path')
const SelectListView = require('atom-select-list')
const { it, fit, ffit, beforeEach, afterEach } = require('./async-spec-helpers') // eslint-disable-line
describe('GrammarSelector', () => {
let [editor, textGrammar, jsGrammar] = []

View File

@@ -1,106 +0,0 @@
/** @babel */
export function beforeEach (fn) {
global.beforeEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
export function afterEach (fn) {
global.afterEach(function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
;['it', 'fit', 'ffit', 'fffit'].forEach(function (name) {
module.exports[name] = function (description, fn) {
if (fn === undefined) {
global[name](description)
return
}
global[name](description, function () {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
})
export async function conditionPromise (
condition,
description = 'anonymous condition'
) {
const startTime = Date.now()
while (true) {
await timeoutPromise(100)
if (await condition()) {
return
}
if (Date.now() - startTime > 5000) {
throw new Error('Timed out waiting on ' + description)
}
}
}
export function timeoutPromise (timeout) {
return new Promise(function (resolve) {
global.setTimeout(resolve, timeout)
})
}
function waitsForPromise (fn) {
const promise = fn()
global.waitsFor('spec promise to resolve', function (done) {
promise.then(done, function (error) {
jasmine.getEnv().currentSpec.fail(error)
done()
})
})
}
export function emitterEventPromise (emitter, event, timeout = 15000) {
return new Promise((resolve, reject) => {
const timeoutHandle = setTimeout(() => {
reject(new Error(`Timed out waiting for '${event}' event`))
}, timeout)
emitter.once(event, () => {
clearTimeout(timeoutHandle)
resolve()
})
})
}
export function promisify (original) {
return function (...args) {
return new Promise((resolve, reject) => {
args.push((err, ...results) => {
if (err) {
reject(err)
} else {
resolve(...results)
}
})
return original(...args)
})
}
}
export function promisifySome (obj, fnNames) {
const result = {}
for (const fnName of fnNames) {
result[fnName] = promisify(obj[fnName])
}
return result
}

View File

@@ -1,7 +1,5 @@
const { shell } = require('electron')
const { it, fit, ffit, afterEach, beforeEach } = require('./async-spec-helpers') // eslint-disable-line no-unused-vars
describe('link package', () => {
beforeEach(async () => {
await atom.packages.activatePackage('language-gfm')

View File

@@ -1,6 +1,5 @@
/** @babel */
import { it } from './async-spec-helpers'
import ApplicationDelegate from '../src/application-delegate'
describe('ApplicationDelegate', function () {

View File

@@ -1,37 +1,3 @@
function beforeEach (fn) {
global.beforeEach(() => {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
function afterEach (fn) {
global.afterEach(() => {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
;['it', 'fit', 'ffit', 'fffit'].forEach(name => {
exports[name] = (description, fn) => {
if (fn === undefined) {
global[name](description)
return
}
global[name](description, () => {
const result = fn()
if (result instanceof Promise) {
waitsForPromise(() => result)
}
})
}
})
async function conditionPromise (
condition,
description = 'anonymous condition'
@@ -57,16 +23,6 @@ function timeoutPromise (timeout) {
})
}
function waitsForPromise (fn) {
const promise = fn()
global.waitsFor('spec promise to resolve', done => {
promise.then(done, error => {
jasmine.getEnv().currentSpec.fail(error)
done()
})
})
}
function emitterEventPromise (emitter, event, timeout = 15000) {
return new Promise((resolve, reject) => {
const timeoutHandle = setTimeout(() => {
@@ -79,34 +35,6 @@ function emitterEventPromise (emitter, event, timeout = 15000) {
})
}
function promisify (original) {
return function (...args) {
return new Promise((resolve, reject) => {
args.push((err, ...results) => {
if (err) {
reject(err)
} else {
resolve(...results)
}
})
return original(...args)
})
}
}
function promisifySome (obj, fnNames) {
const result = {}
for (const fnName of fnNames) {
result[fnName] = promisify(obj[fnName])
}
return result
}
exports.afterEach = afterEach
exports.beforeEach = beforeEach
exports.conditionPromise = conditionPromise
exports.emitterEventPromise = emitterEventPromise
exports.promisify = promisify
exports.promisifySome = promisifySome
exports.timeoutPromise = timeoutPromise

View File

@@ -1,9 +1,4 @@
const {
it,
beforeEach,
afterEach,
conditionPromise
} = require('./async-spec-helpers')
const { conditionPromise } = require('./async-spec-helpers')
const fs = require('fs')
const path = require('path')
const temp = require('temp').track()

View File

@@ -1,6 +1,5 @@
/** @babel */
import { it, beforeEach, afterEach } from './async-spec-helpers'
import { app } from 'remote'
import atomPaths from '../src/atom-paths'
import fs from 'fs-plus'

View File

@@ -1,11 +1,6 @@
const path = require('path')
const fs = require('fs-plus')
const temp = require('temp').track()
const {
it,
beforeEach,
afterEach
} = require('./async-spec-helpers')
const CommandInstaller = require('../src/command-installer')
describe('CommandInstaller on #darwin', () => {

View File

@@ -1,6 +1,5 @@
const CommandRegistry = require('../src/command-registry')
const _ = require('underscore-plus')
const { it, beforeEach, afterEach } = require('./async-spec-helpers')
describe('CommandRegistry', () => {
let registry, parent, child, grandchild

View File

@@ -1,9 +1,3 @@
const {
it,
beforeEach,
afterEach
} = require('./async-spec-helpers')
const fs = require('fs-plus')
const path = require('path')
const temp = require('temp').track()

View File

@@ -2,7 +2,6 @@
const Grim = require('grim')
import { it } from './async-spec-helpers'
import etch from 'etch'
const getNextUpdatePromise = () => etch.getScheduler().nextUpdatePromise

View File

@@ -4,7 +4,6 @@ const temp = require('temp').track()
const { Directory } = require('pathwatcher')
const GitRepository = require('../src/git-repository')
const GitRepositoryProvider = require('../src/git-repository-provider')
const { it, beforeEach } = require('./async-spec-helpers')
describe('GitRepositoryProvider', () => {
let provider

View File

@@ -1,4 +1,3 @@
const { it, beforeEach, afterEach } = require('./async-spec-helpers')
const path = require('path')
const fs = require('fs-plus')
const temp = require('temp').track()

View File

@@ -1,5 +1,3 @@
const { it, beforeEach, afterEach } = require('./async-spec-helpers')
const dedent = require('dedent')
const path = require('path')
const fs = require('fs-plus')

View File

@@ -1,5 +1,3 @@
const { it, beforeEach, afterEach } = require('./async-spec-helpers')
const { HistoryManager, HistoryProject } = require('../src/history-manager')
const StateStore = require('../src/state-store')

View File

@@ -1,7 +1,5 @@
/** @babel */
import { it, beforeEach } from './async-spec-helpers'
import path from 'path'
import { Emitter } from 'event-kit'

View File

@@ -8,7 +8,6 @@ const { Disposable } = require('atom')
const { buildKeydownEvent } = require('../src/keymap-extensions')
const { mockLocalStorage } = require('./spec-helper')
const ModuleCache = require('../src/module-cache')
const { it, beforeEach, afterEach } = require('./async-spec-helpers')
describe('PackageManager', () => {
function createTestElement (className) {

View File

@@ -1,8 +1,6 @@
/** @babel */
import path from 'path'
import { it, beforeEach } from './async-spec-helpers'
import PackageTranspilationRegistry from '../src/package-transpilation-registry'
const originalCompiler = {

View File

@@ -1,9 +1,4 @@
const PaneContainer = require('../src/pane-container')
const {
it,
beforeEach
} = require('./async-spec-helpers')
describe('PaneContainer', () => {
let confirm, params

View File

@@ -3,12 +3,7 @@ const { Emitter } = require('event-kit')
const Grim = require('grim')
const Pane = require('../src/pane')
const PaneContainer = require('../src/pane-container')
const {
it,
beforeEach,
conditionPromise,
timeoutPromise
} = require('./async-spec-helpers')
const { conditionPromise, timeoutPromise } = require('./async-spec-helpers')
describe('Pane', () => {
let confirm, showSaveDialog, deserializerDisposable

View File

@@ -1,23 +1,21 @@
/** @babel */
import { it, beforeEach, afterEach, promisifySome } from './async-spec-helpers'
import tempCb from 'temp'
import fsCb from 'fs-plus'
import temp from 'temp'
import fs from 'fs-plus'
import path from 'path'
import { promisify } from 'util'
import { CompositeDisposable } from 'event-kit'
import { watchPath, stopAllWatchers } from '../src/path-watcher'
tempCb.track()
temp.track()
const fs = promisifySome(fsCb, [
'writeFile',
'mkdir',
'symlink',
'appendFile',
'realpath'
])
const temp = promisifySome(tempCb, ['mkdir'])
const writeFile = promisify(fs.writeFile)
const mkdir = promisify(fs.mkdir)
const appendFile = promisify(fs.appendFile)
const realpath = promisify(fs.realpath)
const tempMkdir = promisify(temp.mkdir)
describe('watchPath', function () {
let subs
@@ -55,14 +53,14 @@ describe('watchPath', function () {
describe('watchPath()', function () {
it('resolves the returned promise when the watcher begins listening', async function () {
const rootDir = await temp.mkdir('atom-fsmanager-test-')
const rootDir = await tempMkdir('atom-fsmanager-test-')
const watcher = await watchPath(rootDir, {}, () => {})
expect(watcher.constructor.name).toBe('PathWatcher')
})
it('reuses an existing native watcher and resolves getStartPromise immediately if attached to a running watcher', async function () {
const rootDir = await temp.mkdir('atom-fsmanager-test-')
const rootDir = await tempMkdir('atom-fsmanager-test-')
const watcher0 = await watchPath(rootDir, {}, () => {})
const watcher1 = await watchPath(rootDir, {}, () => {})
@@ -71,7 +69,7 @@ describe('watchPath', function () {
})
it("reuses existing native watchers even while they're still starting", async function () {
const rootDir = await temp.mkdir('atom-fsmanager-test-')
const rootDir = await tempMkdir('atom-fsmanager-test-')
const [watcher0, watcher1] = await Promise.all([
watchPath(rootDir, {}, () => {}),
@@ -81,7 +79,7 @@ describe('watchPath', function () {
})
it("doesn't attach new watchers to a native watcher that's stopping", async function () {
const rootDir = await temp.mkdir('atom-fsmanager-test-')
const rootDir = await tempMkdir('atom-fsmanager-test-')
const watcher0 = await watchPath(rootDir, {}, () => {})
const native0 = watcher0.native
@@ -93,12 +91,12 @@ describe('watchPath', function () {
})
it('reuses an existing native watcher on a parent directory and filters events', async function () {
const rootDir = await temp.mkdir('atom-fsmanager-test-').then(fs.realpath)
const rootDir = await tempMkdir('atom-fsmanager-test-').then(realpath)
const rootFile = path.join(rootDir, 'rootfile.txt')
const subDir = path.join(rootDir, 'subdir')
const subFile = path.join(subDir, 'subfile.txt')
await fs.mkdir(subDir)
await mkdir(subDir)
// Keep the watchers alive with an undisposed subscription
const rootWatcher = await watchPath(rootDir, {}, () => {})
@@ -111,18 +109,17 @@ describe('watchPath', function () {
waitForChanges(rootWatcher, subFile),
waitForChanges(childWatcher, subFile)
])
await fs.writeFile(subFile, 'subfile\n', { encoding: 'utf8' })
await writeFile(subFile, 'subfile\n', { encoding: 'utf8' })
await firstChanges
const nextRootEvent = waitForChanges(rootWatcher, rootFile)
await fs.writeFile(rootFile, 'rootfile\n', { encoding: 'utf8' })
await writeFile(rootFile, 'rootfile\n', { encoding: 'utf8' })
await nextRootEvent
})
it('adopts existing child watchers and filters events appropriately to them', async function () {
const parentDir = await temp
.mkdir('atom-fsmanager-test-')
.then(fs.realpath)
const parentDir = await tempMkdir('atom-fsmanager-test-')
.then(realpath)
// Create the directory tree
const rootFile = path.join(parentDir, 'rootfile.txt')
@@ -131,12 +128,12 @@ describe('watchPath', function () {
const subDir1 = path.join(parentDir, 'subdir1')
const subFile1 = path.join(subDir1, 'subfile1.txt')
await fs.mkdir(subDir0)
await fs.mkdir(subDir1)
await mkdir(subDir0)
await mkdir(subDir1)
await Promise.all([
fs.writeFile(rootFile, 'rootfile\n', { encoding: 'utf8' }),
fs.writeFile(subFile0, 'subfile 0\n', { encoding: 'utf8' }),
fs.writeFile(subFile1, 'subfile 1\n', { encoding: 'utf8' })
writeFile(rootFile, 'rootfile\n', { encoding: 'utf8' }),
writeFile(subFile0, 'subfile 0\n', { encoding: 'utf8' }),
writeFile(subFile1, 'subfile 1\n', { encoding: 'utf8' })
])
// Begin the child watchers and keep them alive
@@ -162,9 +159,9 @@ describe('watchPath', function () {
// Ensure events are filtered correctly
await Promise.all([
fs.appendFile(rootFile, 'change\n', { encoding: 'utf8' }),
fs.appendFile(subFile0, 'change\n', { encoding: 'utf8' }),
fs.appendFile(subFile1, 'change\n', { encoding: 'utf8' })
appendFile(rootFile, 'change\n', { encoding: 'utf8' }),
appendFile(subFile0, 'change\n', { encoding: 'utf8' }),
appendFile(subFile1, 'change\n', { encoding: 'utf8' })
])
await Promise.all([

View File

@@ -1,6 +1,5 @@
/** @babel */
import { it, beforeEach } from './async-spec-helpers'
import { Disposable } from 'event-kit'
const ReopenProjectMenuManager = require('../src/reopen-project-menu-manager')

View File

@@ -1,5 +1,4 @@
/** @babel */
import { it } from './async-spec-helpers'
const StateStore = require('../src/state-store.js')

View File

@@ -1,10 +1,4 @@
const {
it,
beforeEach,
afterEach,
conditionPromise
} = require('./async-spec-helpers')
const { conditionPromise } = require('./async-spec-helpers')
const Random = require('../script/node_modules/random-seed')
const { getRandomBufferRange, buildRandomLines } = require('./helpers/random')

View File

@@ -1,8 +1,3 @@
const {
it,
beforeEach
} = require('./async-spec-helpers')
const TextEditor = require('../src/text-editor')
const TextEditorElement = require('../src/text-editor-element')

View File

@@ -2,7 +2,6 @@ const TextEditorRegistry = require('../src/text-editor-registry')
const TextEditor = require('../src/text-editor')
const TextBuffer = require('text-buffer')
const { Point, Range } = TextBuffer
const { it } = require('./async-spec-helpers')
const dedent = require('dedent')
describe('TextEditorRegistry', function () {

View File

@@ -1,10 +1,3 @@
const {
it,
beforeEach,
afterEach
} = require('./async-spec-helpers')
const fs = require('fs')
const path = require('path')
const temp = require('temp').track()

View File

@@ -4,7 +4,6 @@ const TextBuffer = require('text-buffer')
const { Point } = TextBuffer
const _ = require('underscore-plus')
const dedent = require('dedent')
const { it, beforeEach, afterEach } = require('./async-spec-helpers')
describe('TextMateLanguageMode', () => {
let languageMode, buffer, config

View File

@@ -1,7 +1,5 @@
/* eslint-disable no-template-curly-in-string */
const { it, beforeEach, afterEach } = require('./async-spec-helpers')
const fs = require('fs')
const path = require('path')
const dedent = require('dedent')

View File

@@ -1,7 +1,5 @@
/** @babel */
/* eslint-env jasmine */
import { it, beforeEach, afterEach } from './async-spec-helpers'
import path from 'path'
import childProcess from 'child_process'
import {

View File

@@ -2,8 +2,6 @@
import url from 'url'
import { it } from './async-spec-helpers'
import URIHandlerRegistry from '../src/uri-handler-registry'
describe('URIHandlerRegistry', () => {

View File

@@ -2,8 +2,6 @@
const TextEditor = require('../src/text-editor')
import { it } from './async-spec-helpers'
describe('WorkspaceCenter', () => {
describe('.observeTextEditors()', () => {
it('invokes the observer with current and future text editors', () => {

View File

@@ -5,7 +5,6 @@ const etch = require('etch')
const path = require('path')
const temp = require('temp').track()
const { Disposable } = require('event-kit')
const { it, beforeEach, afterEach } = require('./async-spec-helpers')
const getNextUpdatePromise = () => etch.getScheduler().nextUpdatePromise

View File

@@ -10,12 +10,7 @@ const _ = require('underscore-plus')
const fstream = require('fstream')
const fs = require('fs-plus')
const AtomEnvironment = require('../src/atom-environment')
const {
it,
beforeEach,
afterEach,
conditionPromise
} = require('./async-spec-helpers')
const { conditionPromise } = require('./async-spec-helpers')
describe('Workspace', () => {
let workspace