mocha#Suite TypeScript Examples

The following examples show how to use mocha#Suite. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: info.test.ts    From vscode-lean4 with Apache License 2.0 6 votes vote down vote up
suite('InfoView Test Suite', () => {

    test('Copy to Comment', async () => {

        console.log('=================== Copy to Comment ===================');

        const lean = await initLean4Untitled('#eval 47*22');
        const info = lean.exports.infoProvider;
        assert(info, 'No InfoProvider export');

        await assertStringInInfoview(info, '1034');

        console.log('Clicking copyToComment button in InfoView');
        await info.runTestScript('document.querySelector(\'[data-id*="copy-to-comment"]\').click()');

        console.log("Checking editor contains '1034'")
        const editor = vscode.window.activeTextEditor;
        assert(editor !== undefined, 'no active editor');
        await findWord(editor, '1034');

    }).timeout(60000);

}).timeout(60000);
Example #2
Source File: lean3.test.ts    From vscode-lean4 with Apache License 2.0 6 votes vote down vote up
suite('Lean3 Compatibility Test Suite', () => {

    test('Lean3 project', async () => {
        void vscode.window.showInformationMessage('Running tests: ' + __dirname);

        const testsRoot = path.join(__dirname, '..', '..', '..', '..', 'test', 'test-fixtures', 'lean3');

        const doc = await vscode.workspace.openTextDocument(path.join(testsRoot, 'Main.lean'));
        await vscode.window.showTextDocument(doc);

        await waitForActiveEditor();

        const lean3 = await waitForActiveExtension('jroesch.lean');
        assert(lean3, 'Lean3 extension not loaded');

        const lean = await waitForActiveExtension('leanprover.lean4');
        assert(lean, 'Lean extension not loaded');
        assert(!lean.exports.isLean4Project, 'Lean4 extension should not be running!');

        console.log('Checking vscode commands...');
        const cmds = await vscode.commands.getCommands(true);
        cmds.forEach(cmd => {
            assert(cmd !== 'lean4.selectToolchain', 'Lean4 extension should not have any registered commands');
        });

        await vscode.commands.executeCommand('workbench.action.closeAllEditors');
    });

}).timeout(60000);
Example #3
Source File: multi.test.ts    From vscode-lean4 with Apache License 2.0 6 votes vote down vote up
suite('Multi-Folder Test Suite', () => {

    test('Load a multi-project workspace', async () => {

        console.log('=================== Load Lean Files in a multi-project workspace ===================');
        // make sure test is always run in predictable state, which is no file or folder open
        await vscode.commands.executeCommand('workbench.action.closeAllEditors');
        void vscode.window.showInformationMessage('Running tests: ' + __dirname);

        const testsRoot = path.join(__dirname, '..', '..', '..', '..', 'test', 'test-fixtures', 'multi');
        const lean = await initLean4(path.join(testsRoot, 'test', 'Main.lean'));

        // verify we have a nightly build running in this folder.
        const info = lean.exports.infoProvider;
        assert(info, 'No InfoProvider export');
        await assertStringInInfoview(info, '4.0.0-nightly-');

        // Now open a file from the other project
        const doc2 = await vscode.workspace.openTextDocument(path.join(testsRoot, 'foo', 'Foo.lean'));
        const options : vscode.TextDocumentShowOptions = { preview: false };
        await vscode.window.showTextDocument(doc2, options);

        // verify that a different version of lean is running here (leanprover/lean4:stable)
        await assertStringInInfoview(info, '4.0.0, commit');

        // Now verify we have 2 LeanClients running.
        const clients = lean.exports.clientProvider;
        assert(clients, 'No LeanClientProvider export');
        const actual = clients.getClients().length
        assert(actual === 2, 'Expected 2 LeanClients to be running, but found ' + actual);

        // make sure test is always run in predictable state, which is no file or folder open
        await vscode.commands.executeCommand('workbench.action.closeAllEditors');
    }).timeout(60000);

}).timeout(60000);
Example #4
Source File: mocha.ts    From earl with MIT License 6 votes vote down vote up
function makeSuiteName(testCtx: Suite): string[] {
  if (testCtx.parent) {
    return [...makeSuiteName(testCtx.parent), testCtx.title]
  }
  if (testCtx.title) {
    return [testCtx.title]
  }
  return []
}
Example #5
Source File: export-factory.test.ts    From vscode-code-review with MIT License 5 votes vote down vote up
suite('Export Factory', () => {
  suite('compareLocation', () => {
    const cases = [
      {
        lhs: undefined,
        rhs: undefined,
        expected: 0,
      },
      {
        lhs: { lineStart: 1, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        rhs: undefined,
        expected: -1,
      },
      {
        lhs: undefined,
        rhs: { lineStart: 1, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        expected: 1,
      },
      {
        lhs: { lineStart: 1, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        rhs: { lineStart: 1, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        expected: 0,
      },
      {
        lhs: { lineStart: 1, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        rhs: { lineStart: 2, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        expected: -1,
      },
      {
        lhs: { lineStart: 2, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        rhs: { lineStart: 1, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        expected: 1,
      },
      {
        lhs: { lineStart: 1, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        rhs: { lineStart: 1, columnStart: 2, lineEnd: 1, columnEnd: 1 },
        expected: -1,
      },
      {
        lhs: { lineStart: 1, columnStart: 2, lineEnd: 1, columnEnd: 1 },
        rhs: { lineStart: 1, columnStart: 1, lineEnd: 1, columnEnd: 1 },
        expected: 1,
      },
    ];

    cases.forEach((value, idx) => {
      test(`should compare ${value.expected} (#${idx})`, () => {
        const result = compareLocation(value.lhs, value.rhs);
        assert.strictEqual(result, value.expected);
      });
    });
  });
});
Example #6
Source File: LookupProviderV3.test.ts    From dendron with GNU Affero General Public License v3.0 5 votes vote down vote up
suite("LookupProviderV3 utility methods:", () => {
  describe(`shouldBubbleUpCreateNew`, () => {
    describe(`WHEN no special characters and no exact matches`, () => {
      let querystring: string;
      let numberOfExactMatches: number;

      beforeEach(() => {
        querystring = "simple-query-no-special-chars";
        numberOfExactMatches = 0;
      });

      it(`AND bubble up is omitted THEN bubble up`, () => {
        expect(
          shouldBubbleUpCreateNew({ querystring, numberOfExactMatches })
        ).toBeTruthy();

        expect(
          shouldBubbleUpCreateNew({
            querystring,
            numberOfExactMatches,
            bubbleUpCreateNew: undefined,
          })
        ).toBeTruthy();
      });

      it("AND bubble up is set to false THEN do NOT bubble up", () => {
        const actual = shouldBubbleUpCreateNew({
          querystring,
          numberOfExactMatches,
          bubbleUpCreateNew: false,
        });
        expect(actual).toBeFalsy();
      });

      it("AND bubble up is set to true THEN bubble up", () => {
        const actual = shouldBubbleUpCreateNew({
          querystring,
          numberOfExactMatches,
          bubbleUpCreateNew: true,
        });
        expect(actual).toBeTruthy();
      });
    });

    it(`WHEN special char is used THEN do NOT bubble up`, () => {
      const actual = shouldBubbleUpCreateNew({
        querystring: "query with space",
        numberOfExactMatches: 0,
      });
      expect(actual).toBeFalsy();
    });

    it(`WHEN number of exact matches is more than 0 THEN do NOT bubble up`, () => {
      const actual = shouldBubbleUpCreateNew({
        querystring: "query-val",
        numberOfExactMatches: 1,
      });
      expect(actual).toBeFalsy();
    });
  });

  describe(`sortBySimilarity`, () => {
    it("WHEN notes out of order THEN sort by similarity", async () => {
      const noteFactory = TestNoteFactory.defaultUnitTestFactory();

      const notes = [
        await noteFactory.createForFName("pkg.hi.components"),
        await noteFactory.createForFName("pkg.hi.arch"),
        await noteFactory.createForFName("pkg.hi.quickstart"),
      ];

      const sorted = sortBySimilarity(notes, "pkg.hi.arc");
      expect(sorted.map((sorted) => sorted.fname)).toEqual([
        "pkg.hi.arch",
        "pkg.hi.quickstart",
        "pkg.hi.components",
      ]);
    });
  });
});
Example #7
Source File: docview.test.ts    From vscode-lean4 with Apache License 2.0 5 votes vote down vote up
suite('Documentation View Test Suite', () => {

    test('Documentation View Example Test', async () => {
        // This test opens the documentation view and selects the "Example" link.
        console.log('=================== Documentation View Example Test ===================');

        void vscode.window.showInformationMessage('Running tests: ' + __dirname);
        const testsRoot = path.join(__dirname, '..', '..', '..', '..', 'test', 'test-fixtures', 'simple');
        const mainFile = path.join(testsRoot, 'Main.lean');
        const lean = await initLean4(mainFile);

        const info = lean.exports.infoProvider;
        assert(info, 'No InfoProvider export');
        const expectedVersion = 'Hello:';
        let html = await waitForInfoviewHtml(info, expectedVersion);
        const versionString = extractPhrase(html, 'Hello:', '<').trim();
        console.log(`>>> Found "${versionString}" in infoview`)

        await vscode.commands.executeCommand('lean4.docView.open');

        const docView = lean.exports.docView;
        assert(docView, 'No docView export');
        const expectedMenuItem = 'Abbreviations cheat sheet';
        html = await waitForDocViewHtml(docView, expectedMenuItem);

        // invoke the TPIL link
        await invokeHrefCommand(html, 'a[href*="theorem_proving_in_lean4"]');
        html = await waitForDocViewHtml(docView, 'Computers and Theorem Proving');
        await delay(1000); // just so we can see it while debugging

        // go back to menu
        await invokeHrefCommand(html, 'a[href*="lean4.docView.back"]');
        html = await waitForDocViewHtml(docView, expectedMenuItem);
        await delay(1000); // just so we can see it while debugging

        // invoke the command in the <a> tag with href containing 'openExample
        await invokeHrefCommand(html, 'a[href*="openExample"]')

        const example = await waitForActiveEditor('Untitled-1');
        assert(example, 'Example file not opened');

        // the example should be active and should be showing this in the info view.
        const exampleOuput = 'Hello, world!';
        await waitForInfoviewHtml(info, exampleOuput);

        // make sure test is always run in predictable state, which is no file or folder open
        await vscode.commands.executeCommand('workbench.action.closeAllEditors');

    }).timeout(60000);

}).timeout(60000);
Example #8
Source File: extension.test.ts    From vscode-fzf-quick-open with MIT License 5 votes vote down vote up
suite('fzf quick open uninit', async () => {
	vscode.window.showInformationMessage('Start all tests.');
	test('Commands not registered', () => {
		// Commands not yet present
		vscode.commands.getCommands().then((cmds) => {
		expect(cmds.indexOf('fzf-quick-open.runFzfFile')).eq(-1);
		expect(cmds.indexOf('fzf-quick-open.runFzfFilePwd')).eq(-1);
		expect(cmds.indexOf('fzf-quick-open.runFzfAddWorkspaceFolder')).eq(-1);
		expect(cmds.indexOf('fzf-quick-open.runFzfAddWorkspaceFolderPwd')).eq(-1);
		expect(cmds.indexOf('fzf-quick-open.runFzfSSearch')).eq(-1);
		expect(cmds.indexOf('fzf-quick-open.runFzfSearchPwd')).eq(-1);
		})
	});

	//activateExtension();

	test('Load extension', async () => {
		await activateExtension();
		await verifyCommandsRegistered();
	});

	test('Open file', async () => {
		await runCommandAndVerifyFzfTerminal('fzf-quick-open.runFzfFile', vscode.window.terminals.length + 1, fzfQuickOpen.TERMINAL_NAME);
		await verifyCommandsRegistered();
	})

	test('Add workspace folder', async () => {
		await runCommandAndVerifyFzfTerminal('fzf-quick-open.runFzfAddWorkspaceFolder', vscode.window.terminals.length, fzfQuickOpen.TERMINAL_NAME)
		await verifyCommandsRegistered();
	})

	test('2 commands 1 terminal', async () => {
		// Make a test terminal for more coverage
		await vscode.window.createTerminal("Test terminal");
		await runCommandAndVerifyFzfTerminal('fzf-quick-open.runFzfFile', vscode.window.terminals.length, fzfQuickOpen.TERMINAL_NAME);
		// Calling 2nd command should reuse terminal
		await runCommandAndVerifyFzfTerminal('fzf-quick-open.runFzfAddWorkspaceFolder', vscode.window.terminals.length, fzfQuickOpen.TERMINAL_NAME);
	});

	test('Open file pwd', async () => {
		await runCommandAndVerifyFzfTerminal('fzf-quick-open.runFzfFilePwd', vscode.window.terminals.length + 1, fzfQuickOpen.TERMINAL_NAME_PWD)
		await verifyCommandsRegistered();
	})

	test('Add workspace folder pwd', async () => {
		await runCommandAndVerifyFzfTerminal('fzf-quick-open.runFzfAddWorkspaceFolderPwd', vscode.window.terminals.length, fzfQuickOpen.TERMINAL_NAME_PWD)
		await verifyCommandsRegistered();
	})

	async function verifyRgConfig(opt: fzfQuickOpen.rgoptions, flag: string) {
		let settings = vscode.workspace.getConfiguration('fzf-quick-open');
		await settings.update('ripgrepSearchStyle', opt, vscode.ConfigurationTarget.Global);
		let testFlag = '--a-test-flag --other-test-flag';
		await settings.update('ripgrepOptions', testFlag, vscode.ConfigurationTarget.Global);
		let rgcmd = fzfQuickOpen.makeSearchCmd('pattern');
		let expectedFlag = fzfQuickOpen.rgflagmap.get(opt);
		expect(rgcmd).contains(expectedFlag);
		expect(rgcmd).contains(flag);
		expect(rgcmd).contains(testFlag);
	}

	// Make sure we respond to configuration changes when computing rg command
	test('Rg configuration', async () => {
		await verifyRgConfig(fzfQuickOpen.rgoptions.CaseSensitive, "--case-sensitive")
		await verifyRgConfig(fzfQuickOpen.rgoptions.IgnoreCase, "--ignore-case");
		await verifyRgConfig(fzfQuickOpen.rgoptions.SmartCase, "--smart-case");
	})
});
Example #9
Source File: LookupProviderV3.test.ts    From dendron with GNU Affero General Public License v3.0 4 votes vote down vote up
suite("selection2Items", () => {
  const ctx: ExtensionContext = setupBeforeAfter(this, {
    noSetTimeout: true,
  });
  let active: NoteProps;
  let activeWithAmbiguousLink: NoteProps;
  let activeWithNonUniqueLinks: NoteProps;
  describeMultiWS(
    "GIVEN an active note with selection that contains wikilinks",
    {
      ctx,
      preSetupHook: async ({ vaults, wsRoot }) => {
        await ENGINE_HOOKS.setupBasic({ vaults, wsRoot });
        active = await NoteTestUtilsV4.createNote({
          vault: TestEngineUtils.vault1(vaults),
          wsRoot,
          fname: "active",
          body: "[[dendron.ginger]]\n[[dendron.dragonfruit]]\n[[dendron.clementine]]",
        });
        activeWithAmbiguousLink = await NoteTestUtilsV4.createNote({
          vault: TestEngineUtils.vault1(vaults),
          wsRoot,
          fname: "active-ambiguous",
          body: "[[pican]]",
        });
        activeWithNonUniqueLinks = await NoteTestUtilsV4.createNote({
          vault: TestEngineUtils.vault1(vaults),
          wsRoot,
          fname: "active-dedupe",
          body: "[[dendron.ginger]]\n\n[[Ginger|dendron.ginger]]\n\n[[Lots of Ginger|dendron.ginger]]\n\n",
        });
        await NoteTestUtilsV4.createNote({
          genRandomId: true,
          vault: TestEngineUtils.vault2(vaults),
          wsRoot,
          fname: "pican",
          body: "",
        });
        await NoteTestUtilsV4.createNote({
          genRandomId: true,
          vault: TestEngineUtils.vault3(vaults),
          wsRoot,
          fname: "pican",
          body: "",
        });
        await NoteTestUtilsV4.createNote({
          vault: TestEngineUtils.vault1(vaults),
          wsRoot,
          fname: "dendron.ginger",
          body: "",
        });
        await NoteTestUtilsV4.createNote({
          vault: TestEngineUtils.vault1(vaults),
          wsRoot,
          fname: "dendron.dragonfruit",
          body: "",
        });
        await NoteTestUtilsV4.createNote({
          vault: TestEngineUtils.vault1(vaults),
          wsRoot,
          fname: "dendron.clementine",
          body: "",
        });
      },
    },
    () => {
      test("THEN quickpick is populated with notes that were selected.", async () => {
        const editor = await WSUtils.openNote(active);
        editor.selection = new Selection(7, 0, 10, 0);

        const cmd = new NoteLookupCommand();
        const gatherOut = await cmd.gatherInputs({
          selectionType: "selection2Items",
          initialValue: "",
          noConfirm: true,
        });

        const enrichOut = await cmd.enrichInputs(gatherOut);

        expect(
          !_.isUndefined(gatherOut.quickpick.itemsFromSelection)
        ).toBeTruthy();
        const expectedItemLabels = [
          "dendron.ginger",
          "dendron.dragonfruit",
          "dendron.clementine",
        ];

        const actualItemLabels = enrichOut?.selectedItems.map(
          (item) => item.label
        );

        expect(expectedItemLabels).toEqual(actualItemLabels);

        cmd.cleanUp();
      });

      test("THEN quickpick is populated with normal query results.", async () => {
        const editor = await WSUtils.openNote(active);
        editor.selection = new Selection(7, 0, 10, 0);

        const cmd = new NoteLookupCommand();
        const gatherOut = await cmd.gatherInputs({
          noConfirm: true,
          initialValue: "",
        });

        const enrichOut = await cmd.enrichInputs(gatherOut);
        const expectedItemLabels = [
          "root",
          "root",
          "root",
          "active-ambiguous",
          "active-dedupe",
          "active",
          "bar",
          "foo",
          "pican",
          "dendron",
          "pican",
        ];

        expect(
          _.isUndefined(gatherOut.quickpick.itemsFromSelection)
        ).toBeTruthy();

        const actualItemLabels = enrichOut?.selectedItems.map(
          (item) => item.label
        );
        expect(expectedItemLabels.sort()).toEqual(actualItemLabels?.sort());

        cmd.cleanUp();
      });

      test("THEN if selected wikilink's vault is ambiguous, list all notes with same fname across all vaults.", async () => {
        const editor = await WSUtils.openNote(activeWithAmbiguousLink);
        editor.selection = new Selection(7, 0, 8, 0);

        const cmd = new NoteLookupCommand();
        const gatherOut = await cmd.gatherInputs({
          noConfirm: true,
          selectionType: "selection2Items",
          initialValue: "",
        });

        const enrichOut = await cmd.enrichInputs(gatherOut);
        const expectedItemLabels = ["pican", "pican"];

        expect(
          !_.isUndefined(gatherOut.quickpick.itemsFromSelection)
        ).toBeTruthy();

        const actualItemLabels = enrichOut?.selectedItems.map(
          (item) => item.label
        );

        expect(expectedItemLabels).toEqual(actualItemLabels);

        cmd.cleanUp();
      });

      test("THEN if selection contains links that point to same note, correctly dedupes them", async () => {
        const editor = await WSUtils.openNote(activeWithNonUniqueLinks);
        editor.selection = new Selection(7, 0, 10, 0);

        const cmd = new NoteLookupCommand();
        const gatherOut = await cmd.gatherInputs({
          noConfirm: true,
          selectionType: "selection2Items",
          initialValue: "",
        });

        const enrichOut = await cmd.enrichInputs(gatherOut);
        const expectedItemLabels = ["dendron.ginger"];

        expect(
          !_.isUndefined(gatherOut.quickpick.itemsFromSelection)
        ).toBeTruthy();

        const actualItemLabels = enrichOut?.selectedItems.map(
          (item) => item.label
        );

        expect(expectedItemLabels).toEqual(actualItemLabels);

        cmd.cleanUp();
      });
    }
  );
});
Example #10
Source File: MigrateSelfContainedVault.test.ts    From dendron with GNU Affero General Public License v3.0 4 votes vote down vote up
suite("GIVEN the MigrateSelfContainedVault command", () => {
  describeSingleWS(
    "WHEN the vault prompt is cancelled",
    { selfContained: false },
    () => {
      let showErrorMessage: SinonStubbedFn<typeof window["showErrorMessage"]>;
      let reloadWindow: SinonStubbedFn<typeof VSCodeUtils["reloadWindow"]>;
      let showQuickPick: SinonStubbedFn<typeof VSCodeUtils["showQuickPick"]>;

      before(async () => {
        const cmd = new MigrateSelfContainedVaultCommand(
          ExtensionProvider.getExtension()
        );

        showErrorMessage = sinon.stub(window, "showErrorMessage");
        reloadWindow = sinon.stub(VSCodeUtils, "reloadWindow");
        showQuickPick = sinon
          .stub(VSCodeUtils, "showQuickPick")
          .resolves(undefined);

        await cmd.run();
      });
      after(() => {
        [showErrorMessage, reloadWindow, showQuickPick].forEach((stub) =>
          stub.restore()
        );
      });

      test("THEN the workspace did not reload since there was no migration", () => {
        expect(reloadWindow.called).toBeFalsy();
      });

      test("THEN the vault should not have migrated", async () => {
        const { wsRoot, vaults } = ExtensionProvider.getDWorkspace();
        expect(
          await verifyVaultNotMigrated({ wsRoot, vault: vaults[0] })
        ).toBeTruthy();
      });
    }
  );

  describeSingleWS(
    "WHEN the backup prompt is cancelled",
    { selfContained: false },
    () => {
      let showErrorMessage: SinonStubbedFn<typeof window["showErrorMessage"]>;
      let reloadWindow: SinonStubbedFn<typeof VSCodeUtils["reloadWindow"]>;
      let showQuickPick: SinonStubbedFn<typeof VSCodeUtils["showQuickPick"]>;

      before(async () => {
        const cmd = new MigrateSelfContainedVaultCommand(
          ExtensionProvider.getExtension()
        );

        showErrorMessage = sinon.stub(window, "showErrorMessage");
        reloadWindow = sinon.stub(VSCodeUtils, "reloadWindow");
        const { vaults } = ExtensionProvider.getDWorkspace();
        showQuickPick = stubMigrateQuickPick(
          VaultUtils.getName(vaults[0]),
          MigrateVaultContinueOption.cancel
        );

        await cmd.run();
      });
      after(() => {
        [showErrorMessage, reloadWindow, showQuickPick].forEach((stub) =>
          stub.restore()
        );
      });

      test("THEN the workspace did not reload since there was no migration", () => {
        expect(reloadWindow.called).toBeFalsy();
      });

      test("THEN the vault should not have migrated", async () => {
        const { wsRoot, vaults } = ExtensionProvider.getDWorkspace();
        expect(
          await verifyVaultNotMigrated({ wsRoot, vault: vaults[0] })
        ).toBeTruthy();
      });
    }
  );

  describeSingleWS(
    "WHEN there's only a single vault, and it's self contained",
    { selfContained: true },
    () => {
      let showErrorMessage: SinonStubbedFn<typeof window["showErrorMessage"]>;
      let reloadWindow: SinonStubbedFn<typeof VSCodeUtils["reloadWindow"]>;
      let showQuickPick: SinonStubbedFn<typeof VSCodeUtils["showQuickPick"]>;

      before(async () => {
        const cmd = new MigrateSelfContainedVaultCommand(
          ExtensionProvider.getExtension()
        );

        showErrorMessage = sinon.stub(window, "showErrorMessage");
        reloadWindow = sinon.stub(VSCodeUtils, "reloadWindow");
        showQuickPick = sinon.stub(VSCodeUtils, "showQuickPick");

        await cmd.run();
      });
      after(() => {
        [showErrorMessage, reloadWindow, showQuickPick].forEach((stub) =>
          stub.restore()
        );
      });

      test("THEN there's an error that there's nothing to migrate", () => {
        expect(showErrorMessage.calledOnce).toBeTruthy();
        expect(showErrorMessage.args[0][0].includes("no vault")).toBeTruthy();
      });

      test("THEN no vault is prompted for", () => {
        expect(showQuickPick.called).toBeFalsy();
      });

      test("THEN the workspace did not reload since there was no migration", () => {
        expect(reloadWindow.called).toBeFalsy();
      });
    }
  );

  describeSingleWS(
    "WHEN there's only a single vault, and it's not self contained",
    {
      selfContained: false,
      modConfigCb: (config) => {
        const vault = ConfigUtils.getVaults(config)[0];
        // Using an asset in the vault as the logo. Migration should update the path.
        ConfigUtils.setPublishProp(
          config,
          "logoPath",
          `${vault.fsPath}/assets/image.png`
        );
        return config;
      },
      postSetupHook: async ({ wsRoot, vaults }) => {
        const vaultPath = pathForVaultRoot({ wsRoot, vault: vaults[0] });
        // Mock git folder & files to see if migration handles them.
        await fs.ensureDir(path.join(vaultPath, ".git"));
        await fs.writeFile(path.join(vaultPath, ".gitignore"), "");
        // Also mock the logo file
        await fs.ensureDir(path.join(vaultPath, "assets"));
        await fs.writeFile(path.join(vaultPath, "assets", "image.png"), "");
      },
    },
    () => {
      let reloadWindow: SinonStubbedFn<typeof VSCodeUtils["reloadWindow"]>;
      let showQuickPick: SinonStubbedFn<typeof VSCodeUtils["showQuickPick"]>;

      before(async () => {
        const { vaults } = ExtensionProvider.getDWorkspace();
        const cmd = new MigrateSelfContainedVaultCommand(
          ExtensionProvider.getExtension()
        );

        reloadWindow = sinon.stub(VSCodeUtils, "reloadWindow");
        showQuickPick = stubMigrateQuickPick(VaultUtils.getName(vaults[0]));

        await cmd.run();
      });
      after(() => {
        [reloadWindow, showQuickPick].forEach((stub) => stub.restore());
      });

      test("THEN it prompts for the vault and confirmation", () => {
        expect(showQuickPick.callCount).toEqual(2);
      });

      test("THEN the workspace reloads to apply the migration", () => {
        expect(reloadWindow.called).toBeTruthy();
      });

      test("THEN the vault is migrated", async () => {
        const { wsRoot, vaults } = ExtensionProvider.getDWorkspace();
        expect(
          verifyVaultHasMigrated({ wsRoot, vault: vaults[0] })
        ).toBeTruthy();
      });

      test("THEN the logoPath is updated to account for the moved asset", async () => {
        const { wsRoot, config } = ExtensionProvider.getDWorkspace();
        const logoPath = ConfigUtils.getPublishing(config).logoPath;
        expect(logoPath).toBeTruthy();
        // If the logoPath was not updated, then we won't find the asset file there
        expect(
          await fs.pathExists(path.join(wsRoot, path.normalize(logoPath!)))
        ).toBeTruthy();
      });

      test("THEN the git folders/files are handled correctly", async () => {
        const { wsRoot, vaults } = ExtensionProvider.getDWorkspace();
        expect(
          await fs.pathExists(
            path.join(pathForVaultRoot({ vault: vaults[0], wsRoot }), ".git")
          )
        ).toBeTruthy();
        expect(
          await fs.pathExists(
            path.join(
              pathForVaultRoot({ vault: vaults[0], wsRoot }),
              ".gitignore"
            )
          )
        ).toBeTruthy();
      });
    }
  );

  describeMultiWS(
    "WHEN there are multiple vaults",
    { selfContained: false },
    () => {
      let reloadWindow: SinonStubbedFn<typeof VSCodeUtils["reloadWindow"]>;
      let showQuickPick: SinonStubbedFn<typeof VSCodeUtils["showQuickPick"]>;

      before(async () => {
        const { vaults } = ExtensionProvider.getDWorkspace();
        const cmd = new MigrateSelfContainedVaultCommand(
          ExtensionProvider.getExtension()
        );

        reloadWindow = sinon.stub(VSCodeUtils, "reloadWindow");
        showQuickPick = stubMigrateQuickPick(VaultUtils.getName(vaults[0]));

        await cmd.run();
      });
      after(() => {
        [reloadWindow, showQuickPick].forEach((stub) => stub.restore());
      });

      test("THEN it prompts for the vault and confirmation", () => {
        expect(showQuickPick.callCount).toEqual(2);
      });

      test("THEN the workspace reloads to apply the migration", () => {
        expect(reloadWindow.called).toBeTruthy();
      });

      test("THEN the vault is migrated", async () => {
        const { wsRoot, vaults } = ExtensionProvider.getDWorkspace();
        expect(
          verifyVaultHasMigrated({ wsRoot, vault: vaults[0] })
        ).toBeTruthy();
      });
    }
  );
});
Example #11
Source File: queryStringTransformer.test.ts    From dendron with GNU Affero General Public License v3.0 4 votes vote down vote up
suite("transformQueryString tests:", () => {
  describe(`WHEN given simple string with slashes`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue: "some/string/value",
      });
    });

    it(`THEN convert to query string to spaces`, () => {
      expect(transformed.queryString).toEqual("some string value");
    });

    it(`THEN split by dots is populates with values`, () => {
      expect(transformed.splitByDots).toEqual(["some", "string", "value"]);
    });

    it(`THEN wasMadeFromWikiLink is false`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(false);
    });
  });

  describe(`WHEN given simple string with dots`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue: "some.string.value",
      });
    });

    it(`THEN dots are transformed to spaces`, () => {
      expect(transformed.queryString).toEqual("some string value");
    });

    it(`THEN split by dots is populates with values`, () => {
      expect(transformed.splitByDots).toEqual(["some", "string", "value"]);
    });

    it(`THEN wasMadeFromWikiLink is false`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(false);
    });
  });

  describe(`WHEN onlyDirectChildren is set`, () => {
    [
      ["dev.vs.", "^dev.vs."],
      ["^dev.vs.", "^dev.vs."],
    ].forEach((arr) => {
      it(`WHEN input='${arr[0]}' THEN output is '${arr[1]}'`, () => {
        const transformed = transformQueryString({
          pickerValue: arr[0],
          onlyDirectChildren: true,
        });

        expect(transformed.queryString).toEqual(arr[1]);
      });
    });
  });

  describe(`WHEN given string with dot that ends with a dot`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue: "some.string.value.",
      });
    });

    it(`THEN do NOT split by dots`, () => {
      expect(transformed.queryString).toEqual("some.string.value.");
    });

    it(`THEN split by dots is not populated`, () => {
      expect(transformed.splitByDots).toBeFalsy();
    });

    it(`THEN wasMadeFromWikiLink is false`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(false);
    });
  });

  describe(`WHEN given string with dots and separate search tokens`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue: "some.string.value t1 t2 c1.c2",
      });
    });

    it(`THEN dots of initial string are transformed to spaces`, () => {
      expect(transformed.queryString).toEqual("some string value t1 t2 c1.c2");
    });

    it(`THEN split by dots is populates with values from dotted string`, () => {
      expect(transformed.splitByDots).toEqual(["some", "string", "value"]);
    });

    it(`THEN wasMadeFromWikiLink is false`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(false);
    });
  });

  describe(`WHEN given simple string with space inside and on the side`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue: " some string.value  ",
      });
    });

    it(`THEN trim the side spaces keep the inside space`, () => {
      expect(transformed.queryString).toEqual("some string.value");
    });

    it(`THEN wasMadeFromWikiLink is false`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(false);
    });
  });

  describe(`WHEN given string with OR operator`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({ pickerValue: "v1 | v2" });
    });

    it(`THEN value stays as is`, () => {
      expect(transformed.queryString).toEqual("v1 | v2");
    });

    it(`THEN wasMadeFromWikiLink is false`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(false);
    });
  });

  describe(`WHEN given string with wiki link without description`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue: "[[some.string.value]]",
      });
    });

    it(`THEN strip out wiki link decoration`, () => {
      expect(transformed.queryString).toEqual("some.string.value");
    });

    it(`THEN wasMadeFromWikiLink is true`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(true);
    });
  });

  describe(`WHEN given string with wiki link with side spaces`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue: "  [[some.string.value]]   ",
      });
    });

    it(`THEN strip out spaces and wiki link decoration`, () => {
      expect(transformed.queryString).toEqual("some.string.value");
    });

    it(`THEN wasMadeFromWikiLink is true`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(true);
    });
  });

  describe(`WHEN given string with wiki link with description`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue: "[[some description|some.string.value]]",
      });
    });

    it(`THEN strip out wiki link decoration and description`, () => {
      expect(transformed.queryString).toEqual("some.string.value");
    });

    it(`THEN wasMadeFromWikiLink is true`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(true);
    });
  });

  describe(`WHEN given string fully qualified with wiki link with description`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue: "[[some description|dendron://private/some.string.value]]",
      });
    });

    it(`THEN strip out wiki link decoration and description`, () => {
      expect(transformed.queryString).toEqual("some.string.value");
    });

    it(`THEN wasMadeFromWikiLink is true`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(true);
    });
  });

  describe(`WHEN given string fully qualified with wiki link with description and header`, () => {
    let transformed: TransformedQueryString;

    beforeEach(() => {
      transformed = transformQueryString({
        pickerValue:
          "[[some description|dendron://private.vault/some.string.value#header-val]]",
      });
    });

    // For now since we don't index the headers they need to be stripped out to be able
    // to query for the note.
    it(`THEN strip out wiki link decoration and description and header`, () => {
      expect(transformed.queryString).toEqual("some.string.value");
    });

    it(`THEN wasMadeFromWikiLink is true`, () => {
      expect(transformed.wasMadeFromWikiLink).toEqual(true);
    });

    it(`THEN vaultName is extracted`, () => {
      expect(transformed.vaultName).toEqual("private.vault");
    });
  });
});
Example #12
Source File: simple.test.ts    From vscode-lean4 with Apache License 2.0 4 votes vote down vote up
suite('Lean4 Basics Test Suite', () => {

    test('Untitled Lean File', async () => {

        console.log('=================== Untitled Lean File ===================');
        void vscode.window.showInformationMessage('Running tests: ' + __dirname);

        const lean = await initLean4Untitled('#eval Lean.versionString');
        const info = lean.exports.infoProvider;
        assert(info, 'No InfoProvider export');

        await assertStringInInfoview(info, '4.0.0-nightly-');

        // test goto definition to lean toolchain works
        await waitForActiveEditor();
        let editor = vscode.window.activeTextEditor;
        assert(editor !== undefined, 'no active editor');
        await gotoDefinition(editor, 'versionString');

        // check infoview is working in this new editor, it should be showing the expected type
        // for the versionString function we just jumped to.
        const html = await waitForInfoviewHtml(info, 'Expected type');

        const expected = path.join('.elan', 'toolchains', 'leanprover--lean4---nightly', 'src', 'lean');
        editor = vscode.window.activeTextEditor;
        assert(editor !== undefined, 'no active editor');
        assert(editor.document.uri.fsPath.indexOf(expected) > 0,
            `Active text editor is not located in ${expected}`);

        // make sure lean client is started in the right place.
        const clients = lean.exports.clientProvider;
        assert(clients, 'No LeanClientProvider export');
        clients.getClients().forEach((client) => {
            const leanRoot = client.getWorkspaceFolder();
            if (leanRoot.indexOf('leanprover--lean4---nightly') > 0){
                assert(leanRoot.endsWith('leanprover--lean4---nightly'),
                    'Lean client is not rooted in the \'leanprover--lean4---nightly\' folder');
            }
        });

        // make sure test is always run in predictable state, which is no file or folder open
        await vscode.commands.executeCommand('workbench.action.closeAllEditors');

    }).timeout(60000);

    test('Orphaned Lean File', async () => {

        console.log('=================== Orphaned Lean File ===================');
        void vscode.window.showInformationMessage('Running tests: ' + __dirname);

        const testsRoot = path.join(__dirname, '..', '..', '..', '..', 'test', 'test-fixtures', 'orphan');
        const lean = await initLean4(path.join(testsRoot, 'factorial.lean'));

        const info = lean.exports.infoProvider;
        assert(info, 'No InfoProvider export');
        const expectedVersion = '5040';  // the factorial function works.
        const html = await waitForInfoviewHtml(info, expectedVersion);

        const installer = lean.exports.installer;
        assert(installer, 'No LeanInstaller export');
        const toolChains = await installer.elanListToolChains(null);
        let defaultToolChain = toolChains.find(tc => tc.indexOf('default') > 0);
        if (defaultToolChain) {
            // the IO.appPath should output something like this:
            // FilePath.mk "/home/.elan/toolchains/leanprover--lean4---nightly/bin/lean.exe"
            // So let's try and find the 'leanprover--lean4---nightly' part.
            defaultToolChain = defaultToolChain.replace(' (default)', '').trim();
            defaultToolChain = defaultToolChain.replace('/','--');
            defaultToolChain = defaultToolChain.replace(':','---')
            // make sure this string exists in the info view.
            await waitForInfoviewHtml(info, defaultToolChain);
        }

        // make sure test is always run in predictable state, which is no file or folder open
        await vscode.commands.executeCommand('workbench.action.closeAllEditors');

    }).timeout(60000);

    test('Goto definition in a package folder', async () => {
        console.log('=================== Goto definition in a package folder ===================');
        void vscode.window.showInformationMessage('Running tests: ' + __dirname);

        // Test we can load file in a project folder from a package folder and also
        // have goto definition work showing that the LeanClient is correctly
        // running in the package root.

        // This test is run twice, once as an ad-hoc mode (no folder open)
        // and again using "open folder" mode.

        const testsRoot = path.join(__dirname, '..', '..', '..', '..', 'test', 'test-fixtures', 'simple');
        const lean = await initLean4(path.join(testsRoot, 'Main.lean'));

        const info = lean.exports.infoProvider;
        assert(info, 'No InfoProvider export');
        let expectedVersion = 'Hello:';
        let html = await waitForInfoviewHtml(info, expectedVersion);
        const versionString = extractPhrase(html, 'Hello:', '<').trim();
        console.log(`>>> Found "${versionString}" in infoview`)

        const editor = await waitForActiveEditor();
        await gotoDefinition(editor, 'getLeanVersion');

        // if goto definition worked, then we are in Version.lean and we should see the Lake version string.
        expectedVersion = 'Lake Version:';
        html = await waitForInfoviewHtml(info, expectedVersion);

        // make sure test is always run in predictable state, which is no file or folder open
        await vscode.commands.executeCommand('workbench.action.closeAllEditors');

    }).timeout(60000);

}).timeout(60000);
Example #13
Source File: toolchain.test.ts    From vscode-lean4 with Apache License 2.0 4 votes vote down vote up
// Expects to be launched with folder: ${workspaceFolder}/vscode-lean4/test/suite/simple
suite('Toolchain Test Suite', () => {

	test('Untitled Select Toolchain', async () => {

		console.log('=================== Untitled Select Toolchain ===================');
		void vscode.window.showInformationMessage('Running tests: ' + __dirname);

		const lean = await initLean4Untitled('#eval Lean.versionString');
		const info = lean.exports.infoProvider;
		assert(info, 'No InfoProvider export');
		// wait for infoView to show up.
		await assertStringInInfoview(info, 'All Messages');

		await resetToolchain(lean.exports.clientProvider);

		await assertStringInInfoview(info, '4.0.0-nightly-');

		// Now switch toolchains (simple suite uses leanprover/lean4:nightly by default)
		await vscode.commands.executeCommand('lean4.selectToolchain', 'leanprover/lean4:stable');

		await assertStringInInfoview(info, '4.0.0, commit');

		await resetToolchain(lean.exports.clientProvider);

		// make sure test is always run in predictable state, which is no file or folder open
		await vscode.commands.executeCommand('workbench.action.closeAllEditors');

	}).timeout(60000);

	test('Restart Server', async () => {

		console.log('=================== Test Restart Server ===================');
		void vscode.window.showInformationMessage('Running tests: ' + __dirname);

		// Test we can restart the lean server

		// run this code twice to ensure that it still works after a Restart Server
		for (let i = 0; i < 2; i++) {

			const testsRoot = path.join(__dirname, '..', '..', '..', '..', 'test', 'test-fixtures', 'simple');
			const lean = await initLean4(path.join(testsRoot, 'Main.lean'));

			const info = lean.exports.infoProvider;
			assert(info, 'No InfoProvider export');
			const expectedVersion = 'Hello:';
			const html = await waitForInfoviewHtml(info, expectedVersion);
			const versionString = extractPhrase(html, 'Hello:', '<').trim();
			console.log(`>>> Found "${versionString}" in infoview`);

			// Now invoke the restart server command
			const clients = lean.exports.clientProvider;
			assert(clients, 'No LeanClientProvider export');
			const client = clients.getClientForFolder(vscode.Uri.file(testsRoot));
			if (client) {
				await restartLeanServer(client);
			} else {
				assert(false, 'No LeanClient found for folder');
			}

			// make sure test is always run in predictable state, which is no file or folder open
			await vscode.commands.executeCommand('workbench.action.closeAllEditors');
		}
	}).timeout(60000);

	test('Select toolchain', async () => {
		console.log('=================== Test select toolchain ===================');
		void vscode.window.showInformationMessage('Running tests: ' + __dirname);

        const testsRoot = path.join(__dirname, '..', '..', '..', '..', 'test', 'test-fixtures', 'simple');
		const lean = await initLean4(path.join(testsRoot, 'Main.lean'));

		// verify we have a nightly build running in this folder.
		const info = lean.exports.infoProvider;
		assert(info, 'No InfoProvider export');
		const expectedVersion = '4.0.0-nightly-';
		await waitForInfoviewHtml(info, expectedVersion);

		await resetToolchain(lean.exports.clientProvider);

		// Now switch toolchains (simple suite uses leanprover/lean4:nightly by default)
		await vscode.commands.executeCommand('lean4.selectToolchain', 'leanprover/lean4:stable');

		// verify that we switched to leanprover/lean4:stable
		const expected2 = '4.0.0, commit';
		await waitForInfoviewHtml(info, expected2);

		// Now reset the toolchain back to nightly build.
		await resetToolchain(lean.exports.clientProvider);

		// Now make sure the reset works and we can go back to the previous nightly version.
		await waitForInfoviewHtml(info, expectedVersion);

		// make sure test is always run in predictable state, which is no file or folder open
		await vscode.commands.executeCommand('workbench.action.closeAllEditors');
	}).timeout(60000);

	test('Edit lean-toolchain version', async () => {

		console.log('=================== Test lean-toolchain edits ===================');

        const testsRoot = path.join(__dirname, '..', '..', '..', '..', 'test', 'test-fixtures', 'simple');

		const lean = await initLean4(path.join(testsRoot, 'Main.lean'));

		// turn off the user prompts so restart of lean server happens automatically.
		const info = lean.exports.infoProvider;
		assert(info, 'No InfoProvider export');
		const installer = lean.exports.installer;
        assert(installer, 'No LeanInstaller export');
		installer.setPromptUser(false);

		// wait for info view to show up.
		await assertStringInInfoview(info, 'Hello');

		// Now make sure the toolchain is reset (in case previous test failed).
		await resetToolchain(lean.exports.clientProvider);

		// verify we have a nightly build running in this folder.
		await assertStringInInfoview(info, '4.0.0-nightly-');

		// Now edit the lean-toolchain file.
		const toolchainFile = path.join(testsRoot, 'lean-toolchain');
		const originalContents = fs.readFileSync(toolchainFile, 'utf8').toString();
		assert(originalContents.trim() === 'leanprover/lean4:nightly');
		// Switch to a stable version.
		let expected = 'stable';
		fs.writeFileSync(toolchainFile, 'leanprover/lean4:stable');


		try {
			// verify that we switched to leanprover/lean4:stable
			const html = await assertStringInInfoview(info, '4.0.0, commit');

			// check the path to lean.exe from the `eval IO.appPath`
			const leanPath = extractPhrase(html, 'FilePath.mk', '<').trim();
			console.log(`Found LeanPath: ${leanPath}`)
			assert(leanPath.indexOf(expected), `Lean Path does not contain: ${expected}`);

			// Find out if we have a 'master' toolchain (setup in our workflow: on-push.yml)
			// and use it if it is there
			const toolChains = await installer.elanListToolChains(null);
			const masterToolChain = toolChains.find(tc => tc === 'master');
			if (masterToolChain) {
				expected = 'master'
				// Switch to a linked toolchain version (setup in our workflow: on-push.yml)
				fs.writeFileSync(toolchainFile, masterToolChain);
				// verify that we switched to the master toolchain.
				await assertStringInInfoview(info, expected);
			}

		} finally {
			// make sure we always switch back to original version!
			fs.writeFileSync(toolchainFile, originalContents);
		}

		// Now make sure the reset works and we can go back to the previous nightly version.
		await assertStringInInfoview(info, '4.0.0-nightly-');

		// make sure test is always run in predictable state, which is no file or folder open
		await vscode.commands.executeCommand('workbench.action.closeAllEditors');

	}).timeout(60000);

}).timeout(60000);