Skip to content

Commit

Permalink
Update jasmine to 2.x (#990)
Browse files Browse the repository at this point in the history
* Remove run-tests scripts

Pro:
* Less code to maintain & update
* run-package-tests was unused

Con:
* Lost the formatting

* Drop support for JUnit XML output for tests

Pro:
* Less code to maintain

* Introduce helper/jasmine-singleton to have reference only to the vendored jasmine

* only the vendored version got used during the tests
* don't need to require jasmine multiple times

Clean up vendored jasmine to make it easier to upgrade

Remove checks about global jasmine as we're not setting it anymore

* Move jasmine-test-runner to be under spec/runners

* Introduce jasmine2 test runner

* Improve test runner switcher

* Fix spec files running with jasmine 2

* Upgrade archive-view to use jasmine2 test runner

* Add retry mechanism to jasmine2 test runner

* Write a wrapper to eliminate done callbacks from async tests

* Run flaky spec only on linux

* Fix the non-headless spec runner

Co-authored-by: Andrew Dupont <[email protected]>

* Fix core specs after merging from `master`

* Add ability to specify trailing comment pattern in `runGrammarTests`

* Add list reporter for CI

---------

Co-authored-by: Andrew Dupont <[email protected]>
  • Loading branch information
kiskoza and savetheclocktower authored Mar 7, 2025
1 parent 397d66b commit 708a540
Show file tree
Hide file tree
Showing 95 changed files with 3,869 additions and 3,089 deletions.
1 change: 0 additions & 1 deletion .github/workflows/package-tests-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,3 @@ jobs:

- name: Run ${{ matrix.package }} Tests
run: Xvfb :1 & cd node_modules/${{ matrix.package }} && if test -d spec; then DISPLAY=:1 pulsar --test spec; fi
# run: node -e "require('./script/run-package-tests')(/${{ matrix.package }}/)"
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"engines": {
"node": ">=14"
},
"atomTestRunner": "runners/jasmine2-test-runner",
"license": "MIT",
"electronVersion": "12.2.3",
"resolutions": {
Expand Down Expand Up @@ -87,8 +88,8 @@
"image-view": "file:packages/image-view",
"incompatible-packages": "file:packages/incompatible-packages",
"jasmine-json": "~0.0",
"jasmine-reporters": "1.1.0",
"jasmine-tagged": "^1.1.4",
"jasmine": "2.5.3",
"key-path-helpers": "^0.4.0",
"keybinding-resolver": "file:./packages/keybinding-resolver",
"language-c": "file:packages/language-c",
Expand Down Expand Up @@ -294,7 +295,9 @@
"start": "electron --no-sandbox --enable-logging . -f",
"dist": "node script/electron-builder.js",
"js-docs": "jsdoc2md --files src --configure docs/.jsdoc.json > ./docs/Pulsar-API-Documentation.md",
"private-js-docs": "jsdoc2md --private --files src --configure docs/.jsdoc.json > ./docs/Source-Code-Documentation.md"
"private-js-docs": "jsdoc2md --private --files src --configure docs/.jsdoc.json > ./docs/Source-Code-Documentation.md",
"test:editor": "yarn test:only spec",
"test:only": "yarn start --test"
},
"devDependencies": {
"@electron/notarize": "^1.2.3",
Expand Down
1 change: 1 addition & 0 deletions packages/archive-view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"engines": {
"atom": "*"
},
"atomTestRunner": "runners/jasmine2-test-runner",
"deserializers": {
"ArchiveEditor": "deserialize",
"ArchiveEditorView": "deserialize"
Expand Down
2 changes: 0 additions & 2 deletions packages/archive-view/spec/archive-editor-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const {it, fit, ffit, fffit, beforeEach, afterEach, conditionPromise} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars

const path = require('path')
const ArchiveEditor = require('../lib/archive-editor')
const ArchiveEditorView = require('../lib/archive-editor-view')
Expand Down
12 changes: 6 additions & 6 deletions packages/archive-view/spec/archive-editor-view-spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {Disposable, File} = require('atom')
const getIconServices = require('../lib/get-icon-services')
const {it, fit, ffit, fffit, beforeEach, afterEach, conditionPromise} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars
const {conditionPromise} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars

async function condition (handler) {
if (jasmine.isSpy(window.setTimeout)) {
Expand All @@ -13,21 +13,21 @@ describe('ArchiveEditorView', () => {
let archiveEditorView, onDidChangeCallback, onDidRenameCallback, onDidDeleteCallback

beforeEach(async () => {
spyOn(File.prototype, 'onDidChange').andCallFake(function (callback) {
spyOn(File.prototype, 'onDidChange').and.callFake(function (callback) {
if (/\.tar$/.test(this.getPath())) {
onDidChangeCallback = callback
}
return new Disposable()
})

spyOn(File.prototype, 'onDidRename').andCallFake(function (callback) {
spyOn(File.prototype, 'onDidRename').and.callFake(function (callback) {
if (/\.tar$/.test(this.getPath())) {
onDidRenameCallback = callback
}
return new Disposable()
})

spyOn(File.prototype, 'onDidDelete').andCallFake(function (callback) {
spyOn(File.prototype, 'onDidDelete').and.callFake(function (callback) {
if (/\.tar$/.test(this.getPath())) {
onDidDeleteCallback = callback
}
Expand Down Expand Up @@ -150,9 +150,9 @@ describe('ArchiveEditorView', () => {

describe('when the file is renamed', () => {
it('refreshes the view and updates the title', async () => {
spyOn(File.prototype, 'getPath').andReturn('nested-renamed.tar')
spyOn(File.prototype, 'getPath').and.returnValue('nested-renamed.tar')
await condition(() => archiveEditorView.element.querySelectorAll('.entry').length > 0)
spyOn(archiveEditorView, 'refresh').andCallThrough()
spyOn(archiveEditorView, 'refresh').and.callThrough()
spyOn(archiveEditorView, 'getTitle')
onDidRenameCallback()
expect(archiveEditorView.refresh).toHaveBeenCalled()
Expand Down
82 changes: 1 addition & 81 deletions packages/archive-view/spec/async-spec-helpers.js
Original file line number Diff line number Diff line change
@@ -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') {
const startTime = Date.now()

Expand All @@ -50,54 +16,8 @@ export async function conditionPromise (condition, description = 'anonymous cond
}
}

export function timeoutPromise (timeout) {
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
}
7 changes: 2 additions & 5 deletions script/electron-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ let options = {

// Core Repo Test Inclusions
"spec/jasmine-test-runner.js",
"spec/spec-helper.js",
"spec/jasmine-junit-reporter.js",
"spec/spec-helper-functions.js",
"spec/atom-reporter.js",
"spec/jasmine-list-reporter.js",
"spec/helpers/**/*",
"spec/runners/**/*",

// --- Exclusions ---
// Core Repo Exclusions
Expand Down
20 changes: 0 additions & 20 deletions script/run-package-tests.js

This file was deleted.

76 changes: 0 additions & 76 deletions script/run-tests.js

This file was deleted.

Loading

0 comments on commit 708a540

Please sign in to comment.