Dendron Extension Testing Internals

Details

To test VSCode, we mock the vscode extension object to let us simulate test in new workspaces. You can see the testing harness here.

Writing tests is described here

This isn't perfect as there are still certain features we cannot test (eg. workspace.onDid* events - these rely watching a current workspace which is not actually constructed for testing). In these cases, we currently implement workarounds like Exposing private methods to tests.

Logic

Execution

describeMultiWs

Code

describeMultiWS(opts, fn) {
	describe {
		before {
			opts?.beforeHook
			setupLegacyWorkspaceMulti(opts)
			opts?.preActivateHook()
			_activate(opts.ctx)
		}

		fn();

		after {
			cleanup
		}
	}

}
setupLegacyWorkspaceMulti(ctx, workspaceType, preSetupHook, modConfigCb, postSetupHook) {
	setupWS
	new StateService(ctx)

	if workspaceType = Code {
		...
	} else {
		...
	}

	preSetupHook
	if workspaceType = Code {
		...
	}

	config = getOrCreate
	modConfigCb(config)
	writeConfig
	postSetupHook

}
setupBeforeAfter(beforeHook) {
	// see [[../packages/plugin-core/src/vsCodeUtils.ts#^7a83pznb91c8]]
	beforeEach {
		opts?.beforeHook()
	}

	afterEach {
		HistoryService.clearSubscriptions()
		opts?.afterHook()
		sinon.restore()
	}
}