Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #63 from atom/wl-decaf
Browse files Browse the repository at this point in the history
Decaffeinate
  • Loading branch information
50Wliu committed Nov 5, 2017
2 parents c3d77ab + d043cdc commit 15e7ef2
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 140 deletions.
1 change: 0 additions & 1 deletion .coffeelintignore

This file was deleted.

37 changes: 0 additions & 37 deletions coffeelint.json

This file was deleted.

60 changes: 0 additions & 60 deletions lib/space-pen-extensions.coffee

This file was deleted.

2 changes: 1 addition & 1 deletion lib/styleguide-view.js
Expand Up @@ -630,7 +630,7 @@ export default class StyleguideView {
`)}

<h2>Icon buttons</h2>
<p>Overview of all <a href="https://octicons.github.com/">Octicons</a>.</p>
<p>Overview of all <a href='https://octicons.github.com/'>Octicons</a>.</p>
{this.renderExampleHTML(dedent`
<div class='block'>
<button class='btn icon icon-gear inline-block-tight'>Settings</button>
Expand Down
17 changes: 0 additions & 17 deletions lib/styleguide.coffee

This file was deleted.

24 changes: 24 additions & 0 deletions lib/styleguide.js
@@ -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)
}
}
17 changes: 13 additions & 4 deletions package.json
Expand Up @@ -7,12 +7,10 @@
"license": "MIT",
"dependencies": {
"atom-select-list": "^0.1.0",
"coffee-script": "~1.8.0",
"dedent": "^0.7.0",
"etch": "0.9.0",
"highlights": "^3.1.1",
"js-beautify": "1.6.14",
"underscore-plus": "^1.0.0"
"js-beautify": "1.6.14"
},
"deserializers": {
"StyleguideView": "createStyleguideView"
Expand All @@ -21,6 +19,17 @@
"atom": "*"
},
"devDependencies": {
"coffeelint": "^1.9.7"
"standard": "^10.0.3"
},
"standard": {
"env": {
"atomtest": true,
"browser": true,
"jasmine": true,
"node": true
},
"globals": [
"atom"
]
}
}
103 changes: 103 additions & 0 deletions spec/async-spec-helpers.js
@@ -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
}
20 changes: 0 additions & 20 deletions spec/styleguide-spec.coffee

This file was deleted.

18 changes: 18 additions & 0 deletions spec/styleguide-spec.js
@@ -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')
})
})
})

0 comments on commit 15e7ef2

Please sign in to comment.