mirror of
https://github.com/mas-cli/mas
synced 2025-02-16 12:38:30 +00:00
🔥 Initialize PromiseKit
This commit is contained in:
parent
7952d0f18f
commit
2ad8695295
30 changed files with 112 additions and 2 deletions
27
Sources/MasKit/MasKit.swift
Normal file
27
Sources/MasKit/MasKit.swift
Normal 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)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,8 @@ import Commandant
|
|||
import Foundation
|
||||
import MasKit
|
||||
|
||||
MasKit.initialize()
|
||||
|
||||
struct StderrOutputStream: TextOutputStream {
|
||||
mutating func write(_ string: String) {
|
||||
fputs(string, stderr)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -36,6 +36,9 @@ public class InfoCommandSpec: QuickSpec {
|
|||
|
||||
"""
|
||||
|
||||
beforeSuite {
|
||||
MasKit.initialize()
|
||||
}
|
||||
describe("Info command") {
|
||||
beforeEach {
|
||||
storeSearch.reset()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -21,6 +21,9 @@ public class SearchCommandSpec: QuickSpec {
|
|||
)
|
||||
let storeSearch = StoreSearchMock()
|
||||
|
||||
beforeSuite {
|
||||
MasKit.initialize()
|
||||
}
|
||||
describe("search command") {
|
||||
beforeEach {
|
||||
storeSearch.reset()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -30,6 +30,7 @@ class MASErrorTestCase: XCTestCase {
|
|||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
MasKit.initialize()
|
||||
nserror = NSError(domain: errorDomain, code: 999)
|
||||
localizedDescription = "foo"
|
||||
}
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue