🔥 Initialize PromiseKit

This commit is contained in:
Chris Araman 2021-04-23 00:01:18 -07:00
parent 7952d0f18f
commit 2ad8695295
No known key found for this signature in database
GPG key ID: BB4499D9E11B61E0
30 changed files with 112 additions and 2 deletions

View file

@ -0,0 +1,27 @@
//
// MasKit.swift
// MasKit
//
// Created by Chris Araman on 4/22/21.
// Copyright © 2021 mas-cli. All rights reserved.
//
import PromiseKit
public enum MasKit {
public static func initialize() {
PromiseKit.conf.Q.map = .global()
PromiseKit.conf.Q.return = .global()
PromiseKit.conf.logHandler = { event in
switch event {
case .waitOnMainThread:
// Ignored. This is a console app that waits on the main thread for
// promises to be processed on the global DispatchQueue.
break
default:
// Other events indicate a programming error.
fatalError("PromiseKit event: \(event)")
}
}
}
}

View file

@ -10,6 +10,8 @@ import Commandant
import Foundation
import MasKit
MasKit.initialize()
struct StderrOutputStream: TextOutputStream {
mutating func write(_ string: String) {
fputs(string, stderr)

View file

@ -13,6 +13,9 @@ import Quick
public class AccountCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("Account command") {
it("displays active account") {
let cmd = AccountCommand()

View file

@ -22,6 +22,9 @@ public class HomeCommandSpec: QuickSpec {
let openCommand = OpenSystemCommandMock()
let cmd = HomeCommand(storeSearch: storeSearch, openCommand: openCommand)
beforeSuite {
MasKit.initialize()
}
describe("home command") {
beforeEach {
storeSearch.reset()

View file

@ -36,6 +36,9 @@ public class InfoCommandSpec: QuickSpec {
"""
beforeSuite {
MasKit.initialize()
}
describe("Info command") {
beforeEach {
storeSearch.reset()

View file

@ -13,6 +13,9 @@ import Quick
public class InstallCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("install command") {
it("installs apps") {
let cmd = InstallCommand()

View file

@ -13,6 +13,9 @@ import Quick
public class ListCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("list command") {
it("lists stuff") {
let list = ListCommand()

View file

@ -13,6 +13,9 @@ import Quick
public class LuckyCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("lucky command") {
it("installs the first app matching a search") {
let cmd = LuckyCommand()

View file

@ -23,6 +23,9 @@ public class OpenCommandSpec: QuickSpec {
let openCommand = OpenSystemCommandMock()
let cmd = OpenCommand(storeSearch: storeSearch, openCommand: openCommand)
beforeSuite {
MasKit.initialize()
}
describe("open command") {
beforeEach {
storeSearch.reset()

View file

@ -13,6 +13,9 @@ import Quick
public class OutdatedCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("outdated command") {
it("displays apps with pending updates") {
let cmd = OutdatedCommand()

View file

@ -13,6 +13,9 @@ import Quick
public class PurchaseCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("purchase command") {
it("purchases apps") {
let cmd = PurchaseCommand()

View file

@ -13,6 +13,9 @@ import Quick
public class ResetCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("reset command") {
it("updates stuff") {
let cmd = ResetCommand()

View file

@ -21,6 +21,9 @@ public class SearchCommandSpec: QuickSpec {
)
let storeSearch = StoreSearchMock()
beforeSuite {
MasKit.initialize()
}
describe("search command") {
beforeEach {
storeSearch.reset()

View file

@ -13,6 +13,9 @@ import Quick
public class SignInCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("signn command") {
it("updates stuff") {
let cmd = SignInCommand()

View file

@ -13,6 +13,9 @@ import Quick
public class SignOutCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("signout command") {
it("updates stuff") {
let cmd = SignOutCommand()

View file

@ -14,6 +14,9 @@ import Quick
public class UninstallCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("uninstall command") {
let appId = 12345
let app = SoftwareProductMock(

View file

@ -13,6 +13,9 @@ import Quick
public class UpgradeCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("upgrade command") {
it("updates stuff") {
let cmd = UpgradeCommand()

View file

@ -22,6 +22,9 @@ public class VendorCommandSpec: QuickSpec {
let openCommand = OpenSystemCommandMock()
let cmd = VendorCommand(storeSearch: storeSearch, openCommand: openCommand)
beforeSuite {
MasKit.initialize()
}
describe("vendor command") {
beforeEach {
storeSearch.reset()

View file

@ -13,6 +13,9 @@ import Quick
public class VersionCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("version command") {
it("displays the current version") {
let cmd = VersionCommand()

View file

@ -15,6 +15,9 @@ public class MasAppLibrarySpec: QuickSpec {
public override func spec() {
let library = MasAppLibrary(softwareMap: SoftwareMapMock(products: apps))
beforeSuite {
MasKit.initialize()
}
describe("mas app library") {
it("contains all installed apps") {
expect(library.installedApps.count) == apps.count

View file

@ -13,6 +13,9 @@ import Quick
public class MasStoreSearchSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("store") {
context("when searched") {
it("can find slack") {

View file

@ -30,6 +30,7 @@ class MASErrorTestCase: XCTestCase {
override func setUp() {
super.setUp()
MasKit.initialize()
nserror = NSError(domain: errorDomain, code: 999)
localizedDescription = "foo"
}

View file

@ -13,6 +13,9 @@ import Quick
public class OpenSystemCommandSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("open system command") {
context("binary path") {
it("defaults to the macOS open command") {

View file

@ -17,6 +17,9 @@ public class AppListsFormatterSpec: QuickSpec {
let format = AppListFormatter.format(products:)
var products: [SoftwareProduct] = []
beforeSuite {
MasKit.initialize()
}
describe("app list formatter") {
beforeEach {
products = []

View file

@ -17,6 +17,9 @@ public class SearchResultsFormatterSpec: QuickSpec {
let format = SearchResultFormatter.format(results:includePrice:)
var results: [SearchResult] = []
beforeSuite {
MasKit.initialize()
}
describe("search results formatter") {
beforeEach {
results = []

View file

@ -14,6 +14,9 @@ import Quick
public class SearchResultListSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("search result list") {
it("can parse bbedit") {
let data = Data(from: "search/bbedit.json")

View file

@ -14,6 +14,9 @@ import Quick
public class SearchResultSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("search result") {
it("can parse things") {
let data = Data(from: "search/things-that-go-bump.json")

View file

@ -11,6 +11,11 @@ import XCTest
@testable import MasKit
class NetworkManagerTests: XCTestCase {
public override func setUp() {
super.setUp()
MasKit.initialize()
}
func testSuccessfulAsyncResponse() {
// Setup our objects
let session = NetworkSessionMock()

View file

@ -15,7 +15,7 @@ class OutputListener {
var contents = ""
init() {
MasKit.printObserver = { [weak self] text in
printObserver = { [weak self] text in
strongify(self) { context in
context.contents += text
}
@ -23,6 +23,6 @@ class OutputListener {
}
deinit {
MasKit.printObserver = nil
printObserver = nil
}
}

View file

@ -13,6 +13,9 @@ import Quick
public class OutputListenerSpec: QuickSpec {
public override func spec() {
beforeSuite {
MasKit.initialize()
}
describe("output listener") {
it("can intercept a single line written stdout") {
let output = OutputListener()