This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from atom/wl-decaf
Decaffeinate
- Loading branch information
Showing
10 changed files
with
159 additions
and
140 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const {CompositeDisposable} = require('atom') | ||
let StyleguideView = null | ||
|
||
const STYLEGUIDE_URI = 'atom://styleguide' | ||
|
||
module.exports = { | ||
activate () { | ||
this.subscriptions = new CompositeDisposable() | ||
this.subscriptions.add(atom.workspace.addOpener(filePath => { | ||
if (filePath === STYLEGUIDE_URI) return this.createStyleguideView({uri: STYLEGUIDE_URI}) | ||
})) | ||
this.subscriptions.add(atom.commands.add('atom-workspace', 'styleguide:show', () => atom.workspace.open(STYLEGUIDE_URI)) | ||
) | ||
}, | ||
|
||
deactivate () { | ||
this.subscriptions.dispose() | ||
}, | ||
|
||
createStyleguideView (state) { | ||
if (StyleguideView == null) StyleguideView = require('./styleguide-view') | ||
return new StyleguideView(state) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** @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 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const {it, fit, ffit, beforeEach, afterEach} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars | ||
|
||
describe('Style Guide', () => { | ||
beforeEach(async () => { | ||
await atom.packages.activatePackage('styleguide') | ||
}) | ||
|
||
describe('the Styleguide view', () => { | ||
let styleGuideView | ||
beforeEach(async () => { | ||
styleGuideView = await atom.workspace.open('atom://styleguide') | ||
}) | ||
|
||
it('opens the style guide', () => { | ||
expect(styleGuideView.element.textContent).toContain('Styleguide') | ||
}) | ||
}) | ||
}) |