|
1 | 1 | import * as assert from "assert"; |
| 2 | +import { suite, test, beforeEach, afterEach } from "mocha"; |
| 3 | +import { activate, deactivate, RubyEnvironmentsApi } from "../extension"; |
| 4 | +import { FakeContext, createContext } from "./helpers"; |
2 | 5 |
|
3 | 6 | suite("Extension Test Suite", () => { |
4 | | - test("Sample test", () => { |
5 | | - assert.strictEqual(1 + 1, 2); |
| 7 | + suite("activate", () => { |
| 8 | + let context: FakeContext; |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + context = createContext(); |
| 12 | + }); |
| 13 | + |
| 14 | + afterEach(() => { |
| 15 | + context.dispose(); |
| 16 | + }); |
| 17 | + |
| 18 | + test("returns an object implementing RubyEnvironmentsApi", async () => { |
| 19 | + const api = activate(context); |
| 20 | + |
| 21 | + assert.strictEqual(typeof api, "object", "activate should return an object"); |
| 22 | + assert.strictEqual(typeof api.activate, "function", "API should have an activate method"); |
| 23 | + assert.strictEqual(typeof api.getRuby, "function", "API should have a getRuby method"); |
| 24 | + assert.strictEqual(typeof api.onDidRubyChange, "function", "API should have an onDidRubyChange event"); |
| 25 | + |
| 26 | + const result = api.activate(undefined); |
| 27 | + assert.ok(result instanceof Promise, "activate should return a Promise"); |
| 28 | + await result; |
| 29 | + }); |
| 30 | + |
| 31 | + test("returned API conforms to RubyEnvironmentsApi interface", () => { |
| 32 | + const api = activate(context); |
| 33 | + |
| 34 | + const typedApi: RubyEnvironmentsApi = api; |
| 35 | + assert.ok(typedApi, "API should conform to RubyEnvironmentsApi interface"); |
| 36 | + }); |
| 37 | + |
| 38 | + test("getRuby returns null initially", () => { |
| 39 | + const api = activate(context); |
| 40 | + |
| 41 | + assert.strictEqual(api.getRuby(), null, "getRuby should return null before activation"); |
| 42 | + }); |
| 43 | + |
| 44 | + test("onDidRubyChange allows subscribing to events", () => { |
| 45 | + const api = activate(context); |
| 46 | + |
| 47 | + let eventFired = false; |
| 48 | + const disposable = api.onDidRubyChange(() => { |
| 49 | + eventFired = true; |
| 50 | + }); |
| 51 | + |
| 52 | + assert.ok(disposable, "onDidRubyChange should return a disposable"); |
| 53 | + assert.strictEqual(typeof disposable.dispose, "function", "disposable should have a dispose method"); |
| 54 | + |
| 55 | + disposable.dispose(); |
| 56 | + assert.strictEqual(eventFired, false, "event should not have fired yet"); |
| 57 | + }); |
| 58 | + |
| 59 | + test("adds event emitter to context subscriptions for disposal", () => { |
| 60 | + assert.strictEqual(context.subscriptions.length, 0, "subscriptions should be empty initially"); |
| 61 | + |
| 62 | + activate(context); |
| 63 | + |
| 64 | + assert.strictEqual(context.subscriptions.length, 1, "should add emitter to subscriptions"); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + suite("deactivate", () => { |
| 69 | + test("can be called without errors", () => { |
| 70 | + assert.doesNotThrow(() => { |
| 71 | + deactivate(); |
| 72 | + }, "deactivate should not throw errors"); |
| 73 | + }); |
6 | 74 | }); |
7 | 75 | }); |
0 commit comments