mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-17 14:07:34 +03:00
Manual decaf deprecation-cop
spec
This commit is contained in:
parent
1a4410e954
commit
a01c200b22
@ -1,36 +0,0 @@
|
||||
DeprecationCopView = require '../lib/deprecation-cop-view'
|
||||
|
||||
describe "DeprecationCop", ->
|
||||
[activationPromise, workspaceElement] = []
|
||||
|
||||
beforeEach ->
|
||||
workspaceElement = atom.views.getView(atom.workspace)
|
||||
activationPromise = atom.packages.activatePackage('deprecation-cop')
|
||||
expect(atom.workspace.getActivePane().getActiveItem()).not.toExist()
|
||||
|
||||
describe "when the deprecation-cop:view event is triggered", ->
|
||||
it "displays the deprecation cop pane", ->
|
||||
atom.commands.dispatch workspaceElement, 'deprecation-cop:view'
|
||||
|
||||
waitsForPromise ->
|
||||
activationPromise
|
||||
|
||||
deprecationCopView = null
|
||||
waitsFor ->
|
||||
deprecationCopView = atom.workspace.getActivePane().getActiveItem()
|
||||
|
||||
runs ->
|
||||
expect(deprecationCopView instanceof DeprecationCopView).toBeTruthy()
|
||||
|
||||
describe "deactivating the package", ->
|
||||
it "removes the deprecation cop pane item", ->
|
||||
atom.commands.dispatch workspaceElement, 'deprecation-cop:view'
|
||||
|
||||
waitsForPromise ->
|
||||
activationPromise
|
||||
|
||||
waitsForPromise ->
|
||||
Promise.resolve(atom.packages.deactivatePackage('deprecation-cop')) # Wrapped for Promise & non-Promise deactivate
|
||||
|
||||
runs ->
|
||||
expect(atom.workspace.getActivePane().getActiveItem()).not.toExist()
|
@ -1,20 +1,16 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
||||
*/
|
||||
|
||||
const DeprecationCopView = require('../lib/deprecation-cop-view');
|
||||
|
||||
describe("DeprecationCop", function() {
|
||||
describe("DeprecationCop", () => {
|
||||
let [activationPromise, workspaceElement] = [];
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
workspaceElement = atom.views.getView(atom.workspace);
|
||||
activationPromise = atom.packages.activatePackage('deprecation-cop');
|
||||
return expect(atom.workspace.getActivePane().getActiveItem()).not.toExist();
|
||||
expect(atom.workspace.getActivePane().getActiveItem()).not.toExist();
|
||||
});
|
||||
|
||||
describe("when the deprecation-cop:view event is triggered", () => it("displays the deprecation cop pane", function() {
|
||||
describe("when the deprecation-cop:view event is triggered", () => it("displays the deprecation cop pane", () => {
|
||||
atom.commands.dispatch(workspaceElement, 'deprecation-cop:view');
|
||||
|
||||
waitsForPromise(() => activationPromise);
|
||||
@ -22,16 +18,16 @@ describe("DeprecationCop", function() {
|
||||
let deprecationCopView = null;
|
||||
waitsFor(() => deprecationCopView = atom.workspace.getActivePane().getActiveItem());
|
||||
|
||||
return runs(() => expect(deprecationCopView instanceof DeprecationCopView).toBeTruthy());
|
||||
runs(() => expect(deprecationCopView instanceof DeprecationCopView).toBeTruthy());
|
||||
}));
|
||||
|
||||
return describe("deactivating the package", () => it("removes the deprecation cop pane item", function() {
|
||||
describe("deactivating the package", () => it("removes the deprecation cop pane item", () => {
|
||||
atom.commands.dispatch(workspaceElement, 'deprecation-cop:view');
|
||||
|
||||
waitsForPromise(() => activationPromise);
|
||||
|
||||
waitsForPromise(() => Promise.resolve(atom.packages.deactivatePackage('deprecation-cop'))); // Wrapped for Promise & non-Promise deactivate
|
||||
|
||||
return runs(() => expect(atom.workspace.getActivePane().getActiveItem()).not.toExist());
|
||||
runs(() => expect(atom.workspace.getActivePane().getActiveItem()).not.toExist());
|
||||
}));
|
||||
});
|
||||
|
@ -1,72 +0,0 @@
|
||||
path = require 'path'
|
||||
Grim = require 'grim'
|
||||
DeprecationCopView = require '../lib/deprecation-cop-view'
|
||||
_ = require 'underscore-plus'
|
||||
|
||||
describe "DeprecationCopStatusBarView", ->
|
||||
[deprecatedMethod, statusBarView, workspaceElement] = []
|
||||
|
||||
beforeEach ->
|
||||
# jasmine.Clock.useMock() cannot mock _.debounce
|
||||
# http://stackoverflow.com/questions/13707047/spec-for-async-functions-using-jasmine
|
||||
spyOn(_, 'debounce').andCallFake (func) ->
|
||||
-> func.apply(this, arguments)
|
||||
|
||||
jasmine.snapshotDeprecations()
|
||||
|
||||
workspaceElement = atom.views.getView(atom.workspace)
|
||||
jasmine.attachToDOM(workspaceElement)
|
||||
waitsForPromise -> atom.packages.activatePackage('status-bar')
|
||||
waitsForPromise -> atom.packages.activatePackage('deprecation-cop')
|
||||
|
||||
waitsFor ->
|
||||
statusBarView = workspaceElement.querySelector('.deprecation-cop-status')
|
||||
|
||||
afterEach ->
|
||||
jasmine.restoreDeprecationsSnapshot()
|
||||
|
||||
it "adds the status bar view when activated", ->
|
||||
expect(statusBarView).toExist()
|
||||
expect(statusBarView.textContent).toBe '0 deprecations'
|
||||
expect(statusBarView).not.toShow()
|
||||
|
||||
it "increments when there are deprecated methods", ->
|
||||
deprecatedMethod = -> Grim.deprecate("This isn't used")
|
||||
anotherDeprecatedMethod = -> Grim.deprecate("This either")
|
||||
expect(statusBarView.style.display).toBe 'none'
|
||||
expect(statusBarView.offsetHeight).toBe(0)
|
||||
|
||||
deprecatedMethod()
|
||||
expect(statusBarView.textContent).toBe '1 deprecation'
|
||||
expect(statusBarView.offsetHeight).toBeGreaterThan(0)
|
||||
|
||||
deprecatedMethod()
|
||||
expect(statusBarView.textContent).toBe '2 deprecations'
|
||||
expect(statusBarView.offsetHeight).toBeGreaterThan(0)
|
||||
|
||||
anotherDeprecatedMethod()
|
||||
expect(statusBarView.textContent).toBe '3 deprecations'
|
||||
expect(statusBarView.offsetHeight).toBeGreaterThan(0)
|
||||
|
||||
# TODO: Remove conditional when the new StyleManager deprecation APIs reach stable.
|
||||
if atom.styles.getDeprecations?
|
||||
it "increments when there are deprecated selectors", ->
|
||||
atom.styles.addStyleSheet("""
|
||||
atom-text-editor::shadow { color: red; }
|
||||
""", sourcePath: 'file-1')
|
||||
expect(statusBarView.textContent).toBe '1 deprecation'
|
||||
expect(statusBarView).toBeVisible()
|
||||
atom.styles.addStyleSheet("""
|
||||
atom-text-editor::shadow { color: blue; }
|
||||
""", sourcePath: 'file-2')
|
||||
expect(statusBarView.textContent).toBe '2 deprecations'
|
||||
expect(statusBarView).toBeVisible()
|
||||
|
||||
it 'opens deprecation cop tab when clicked', ->
|
||||
expect(atom.workspace.getActivePane().getActiveItem()).not.toExist()
|
||||
|
||||
waitsFor (done) ->
|
||||
atom.workspace.onDidOpen ({item}) ->
|
||||
expect(item instanceof DeprecationCopView).toBe true
|
||||
done()
|
||||
statusBarView.click()
|
@ -1,21 +1,16 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const Grim = require('grim');
|
||||
const DeprecationCopView = require('../lib/deprecation-cop-view');
|
||||
const _ = require('underscore-plus');
|
||||
|
||||
describe("DeprecationCopStatusBarView", function() {
|
||||
describe("DeprecationCopStatusBarView", () => {
|
||||
let [deprecatedMethod, statusBarView, workspaceElement] = [];
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
// jasmine.Clock.useMock() cannot mock _.debounce
|
||||
// http://stackoverflow.com/questions/13707047/spec-for-async-functions-using-jasmine
|
||||
spyOn(_, 'debounce').andCallFake(func => (function() { return func.apply(this, arguments); }));
|
||||
spyOn(_, 'debounce').andCallFake(func => (() => { return func.apply(this, arguments); }));
|
||||
|
||||
jasmine.snapshotDeprecations();
|
||||
|
||||
@ -24,18 +19,18 @@ describe("DeprecationCopStatusBarView", function() {
|
||||
waitsForPromise(() => atom.packages.activatePackage('status-bar'));
|
||||
waitsForPromise(() => atom.packages.activatePackage('deprecation-cop'));
|
||||
|
||||
return waitsFor(() => statusBarView = workspaceElement.querySelector('.deprecation-cop-status'));
|
||||
waitsFor(() => statusBarView = workspaceElement.querySelector('.deprecation-cop-status'));
|
||||
});
|
||||
|
||||
afterEach(() => jasmine.restoreDeprecationsSnapshot());
|
||||
|
||||
it("adds the status bar view when activated", function() {
|
||||
it("adds the status bar view when activated", () => {
|
||||
expect(statusBarView).toExist();
|
||||
expect(statusBarView.textContent).toBe('0 deprecations');
|
||||
return expect(statusBarView).not.toShow();
|
||||
expect(statusBarView).not.toShow();
|
||||
});
|
||||
|
||||
it("increments when there are deprecated methods", function() {
|
||||
it("increments when there are deprecated methods", () => {
|
||||
deprecatedMethod = () => Grim.deprecate("This isn't used");
|
||||
const anotherDeprecatedMethod = () => Grim.deprecate("This either");
|
||||
expect(statusBarView.style.display).toBe('none');
|
||||
@ -51,12 +46,12 @@ describe("DeprecationCopStatusBarView", function() {
|
||||
|
||||
anotherDeprecatedMethod();
|
||||
expect(statusBarView.textContent).toBe('3 deprecations');
|
||||
return expect(statusBarView.offsetHeight).toBeGreaterThan(0);
|
||||
expect(statusBarView.offsetHeight).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// TODO: Remove conditional when the new StyleManager deprecation APIs reach stable.
|
||||
if (atom.styles.getDeprecations != null) {
|
||||
it("increments when there are deprecated selectors", function() {
|
||||
it("increments when there are deprecated selectors", () => {
|
||||
atom.styles.addStyleSheet(`\
|
||||
atom-text-editor::shadow { color: red; }\
|
||||
`, {sourcePath: 'file-1'});
|
||||
@ -66,19 +61,19 @@ atom-text-editor::shadow { color: red; }\
|
||||
atom-text-editor::shadow { color: blue; }\
|
||||
`, {sourcePath: 'file-2'});
|
||||
expect(statusBarView.textContent).toBe('2 deprecations');
|
||||
return expect(statusBarView).toBeVisible();
|
||||
expect(statusBarView).toBeVisible();
|
||||
});
|
||||
}
|
||||
|
||||
return it('opens deprecation cop tab when clicked', function() {
|
||||
it('opens deprecation cop tab when clicked', () => {
|
||||
expect(atom.workspace.getActivePane().getActiveItem()).not.toExist();
|
||||
|
||||
return waitsFor(function(done) {
|
||||
waitsFor(function(done) {
|
||||
atom.workspace.onDidOpen(function({item}) {
|
||||
expect(item instanceof DeprecationCopView).toBe(true);
|
||||
return done();
|
||||
done();
|
||||
});
|
||||
return statusBarView.click();
|
||||
statusBarView.click();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,93 +0,0 @@
|
||||
Grim = require 'grim'
|
||||
path = require 'path'
|
||||
_ = require 'underscore-plus'
|
||||
etch = require 'etch'
|
||||
|
||||
describe "DeprecationCopView", ->
|
||||
[deprecationCopView, workspaceElement] = []
|
||||
|
||||
beforeEach ->
|
||||
spyOn(_, 'debounce').andCallFake (func) ->
|
||||
-> func.apply(this, arguments)
|
||||
|
||||
workspaceElement = atom.views.getView(atom.workspace)
|
||||
jasmine.attachToDOM(workspaceElement)
|
||||
|
||||
jasmine.snapshotDeprecations()
|
||||
Grim.clearDeprecations()
|
||||
deprecatedMethod = -> Grim.deprecate("A test deprecation. This isn't used")
|
||||
deprecatedMethod()
|
||||
|
||||
spyOn(Grim, 'deprecate') # Don't fail tests if when using deprecated APIs in deprecation cop's activation
|
||||
activationPromise = atom.packages.activatePackage('deprecation-cop')
|
||||
|
||||
atom.commands.dispatch workspaceElement, 'deprecation-cop:view'
|
||||
|
||||
waitsForPromise ->
|
||||
activationPromise
|
||||
|
||||
waitsFor -> deprecationCopView = atom.workspace.getActivePane().getActiveItem()
|
||||
|
||||
runs ->
|
||||
jasmine.unspy(Grim, 'deprecate')
|
||||
|
||||
afterEach ->
|
||||
jasmine.restoreDeprecationsSnapshot()
|
||||
|
||||
it "displays deprecated methods", ->
|
||||
expect(deprecationCopView.element.textContent).toMatch /Deprecated calls/
|
||||
expect(deprecationCopView.element.textContent).toMatch /This isn't used/
|
||||
|
||||
# TODO: Remove conditional when the new StyleManager deprecation APIs reach stable.
|
||||
if atom.styles.getDeprecations?
|
||||
it "displays deprecated selectors", ->
|
||||
atom.styles.addStyleSheet("atom-text-editor::shadow { color: red }", sourcePath: path.join('some-dir', 'packages', 'package-1', 'file-1.css'))
|
||||
atom.styles.addStyleSheet("atom-text-editor::shadow { color: yellow }", context: 'atom-text-editor', sourcePath: path.join('some-dir', 'packages', 'package-1', 'file-2.css'))
|
||||
atom.styles.addStyleSheet('atom-text-editor::shadow { color: blue }', sourcePath: path.join('another-dir', 'packages', 'package-2', 'file-3.css'))
|
||||
atom.styles.addStyleSheet('atom-text-editor::shadow { color: gray }', sourcePath: path.join('another-dir', 'node_modules', 'package-3', 'file-4.css'))
|
||||
|
||||
promise = etch.getScheduler().getNextUpdatePromise()
|
||||
waitsForPromise -> promise
|
||||
|
||||
runs ->
|
||||
packageItems = deprecationCopView.element.querySelectorAll("ul.selectors > li")
|
||||
expect(packageItems.length).toBe(3)
|
||||
expect(packageItems[0].textContent).toMatch /package-1/
|
||||
expect(packageItems[1].textContent).toMatch /package-2/
|
||||
expect(packageItems[2].textContent).toMatch /Other/
|
||||
|
||||
packageDeprecationItems = packageItems[0].querySelectorAll("li.source-file")
|
||||
expect(packageDeprecationItems.length).toBe(2)
|
||||
expect(packageDeprecationItems[0].textContent).toMatch /atom-text-editor/
|
||||
expect(packageDeprecationItems[0].querySelector("a").href).toMatch('some-dir/packages/package-1/file-1.css')
|
||||
expect(packageDeprecationItems[1].textContent).toMatch /:host/
|
||||
expect(packageDeprecationItems[1].querySelector("a").href).toMatch('some-dir/packages/package-1/file-2.css')
|
||||
|
||||
it 'skips stack entries which go through node_modules/ files when determining package name', ->
|
||||
stack = [
|
||||
{
|
||||
"functionName": "function0"
|
||||
"location": path.normalize "/Users/user/.atom/packages/package1/node_modules/atom-space-pen-viewslib/space-pen.js:55:66"
|
||||
"fileName": path.normalize "/Users/user/.atom/packages/package1/node_modules/atom-space-pen-views/lib/space-pen.js"
|
||||
}
|
||||
{
|
||||
"functionName": "function1"
|
||||
"location": path.normalize "/Users/user/.atom/packages/package1/node_modules/atom-space-pen-viewslib/space-pen.js:15:16"
|
||||
"fileName": path.normalize "/Users/user/.atom/packages/package1/node_modules/atom-space-pen-views/lib/space-pen.js"
|
||||
}
|
||||
{
|
||||
"functionName": "function2"
|
||||
"location": path.normalize "/Users/user/.atom/packages/package2/lib/module.js:13:14"
|
||||
"fileName": path.normalize "/Users/user/.atom/packages/package2/lib/module.js"
|
||||
}
|
||||
]
|
||||
|
||||
packagePathsByPackageName = new Map([
|
||||
['package1', path.normalize("/Users/user/.atom/packages/package1")],
|
||||
['package2', path.normalize("/Users/user/.atom/packages/package2")]
|
||||
])
|
||||
|
||||
spyOn(deprecationCopView, 'getPackagePathsByPackageName').andReturn(packagePathsByPackageName)
|
||||
|
||||
packageName = deprecationCopView.getPackageName(stack)
|
||||
expect(packageName).toBe("package2")
|
@ -1,19 +1,14 @@
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
||||
*/
|
||||
|
||||
const Grim = require('grim');
|
||||
const path = require('path');
|
||||
const _ = require('underscore-plus');
|
||||
const etch = require('etch');
|
||||
|
||||
describe("DeprecationCopView", function() {
|
||||
describe("DeprecationCopView", () => {
|
||||
let [deprecationCopView, workspaceElement] = [];
|
||||
|
||||
beforeEach(function() {
|
||||
spyOn(_, 'debounce').andCallFake(func => (function() { return func.apply(this, arguments); }));
|
||||
beforeEach(() => {
|
||||
spyOn(_, 'debounce').andCallFake(func => (() => { return func.apply(this, arguments); }));
|
||||
|
||||
workspaceElement = atom.views.getView(atom.workspace);
|
||||
jasmine.attachToDOM(workspaceElement);
|
||||
@ -32,19 +27,19 @@ describe("DeprecationCopView", function() {
|
||||
|
||||
waitsFor(() => deprecationCopView = atom.workspace.getActivePane().getActiveItem());
|
||||
|
||||
return runs(() => jasmine.unspy(Grim, 'deprecate'));
|
||||
runs(() => jasmine.unspy(Grim, 'deprecate'));
|
||||
});
|
||||
|
||||
afterEach(() => jasmine.restoreDeprecationsSnapshot());
|
||||
|
||||
it("displays deprecated methods", function() {
|
||||
it("displays deprecated methods", () => {
|
||||
expect(deprecationCopView.element.textContent).toMatch(/Deprecated calls/);
|
||||
return expect(deprecationCopView.element.textContent).toMatch(/This isn't used/);
|
||||
expect(deprecationCopView.element.textContent).toMatch(/This isn't used/);
|
||||
});
|
||||
|
||||
// TODO: Remove conditional when the new StyleManager deprecation APIs reach stable.
|
||||
if (atom.styles.getDeprecations != null) {
|
||||
it("displays deprecated selectors", function() {
|
||||
it("displays deprecated selectors", () => {
|
||||
atom.styles.addStyleSheet("atom-text-editor::shadow { color: red }", {sourcePath: path.join('some-dir', 'packages', 'package-1', 'file-1.css')});
|
||||
atom.styles.addStyleSheet("atom-text-editor::shadow { color: yellow }", {context: 'atom-text-editor', sourcePath: path.join('some-dir', 'packages', 'package-1', 'file-2.css')});
|
||||
atom.styles.addStyleSheet('atom-text-editor::shadow { color: blue }', {sourcePath: path.join('another-dir', 'packages', 'package-2', 'file-3.css')});
|
||||
@ -53,7 +48,7 @@ describe("DeprecationCopView", function() {
|
||||
const promise = etch.getScheduler().getNextUpdatePromise();
|
||||
waitsForPromise(() => promise);
|
||||
|
||||
return runs(function() {
|
||||
runs(() => {
|
||||
const packageItems = deprecationCopView.element.querySelectorAll("ul.selectors > li");
|
||||
expect(packageItems.length).toBe(3);
|
||||
expect(packageItems[0].textContent).toMatch(/package-1/);
|
||||
@ -65,12 +60,12 @@ describe("DeprecationCopView", function() {
|
||||
expect(packageDeprecationItems[0].textContent).toMatch(/atom-text-editor/);
|
||||
expect(packageDeprecationItems[0].querySelector("a").href).toMatch('some-dir/packages/package-1/file-1.css');
|
||||
expect(packageDeprecationItems[1].textContent).toMatch(/:host/);
|
||||
return expect(packageDeprecationItems[1].querySelector("a").href).toMatch('some-dir/packages/package-1/file-2.css');
|
||||
expect(packageDeprecationItems[1].querySelector("a").href).toMatch('some-dir/packages/package-1/file-2.css');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return it('skips stack entries which go through node_modules/ files when determining package name', function() {
|
||||
it('skips stack entries which go through node_modules/ files when determining package name', () => {
|
||||
const stack = [
|
||||
{
|
||||
"functionName": "function0",
|
||||
@ -97,6 +92,6 @@ describe("DeprecationCopView", function() {
|
||||
spyOn(deprecationCopView, 'getPackagePathsByPackageName').andReturn(packagePathsByPackageName);
|
||||
|
||||
const packageName = deprecationCopView.getPackageName(stack);
|
||||
return expect(packageName).toBe("package2");
|
||||
expect(packageName).toBe("package2");
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user