Skip to content

Commit

Permalink
test: fix unit test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Aug 29, 2024
1 parent 9908919 commit 393534e
Show file tree
Hide file tree
Showing 19 changed files with 485 additions and 508 deletions.
32 changes: 16 additions & 16 deletions src/extension/__tests__/__snapshots__/extension.ts.snap
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Extension entry point should create a language client 1`] = `
Array [
[
"Stylelint",
Object {
"debug": Object {
{
"debug": {
"module": "mock-path",
"options": Object {
"execArgv": Array [
"options": {
"execArgv": [
"--nolazy",
"--inspect=6004",
],
},
},
"run": Object {
"run": {
"module": "mock-path",
},
},
Object {
{
"diagnosticCollectionName": "Stylelint",
"documentSelector": Array [
Object {
"documentSelector": [
{
"scheme": "file",
},
Object {
{
"scheme": "untitled",
},
],
"synchronize": Object {
"fileEvents": Array [
"synchronize": {
"fileEvents": [
undefined,
undefined,
],
Expand All @@ -38,11 +38,11 @@ Array [
`;

exports[`Extension entry point with an active text editor, should send auto-fix commands to the language server 1`] = `
Array [
[
"executeCommand",
Object {
"arguments": Array [
Object {
{
"arguments": [
{
"uri": "file:///path/to/file.ts",
"version": 1,
},
Expand Down
68 changes: 21 additions & 47 deletions src/extension/__tests__/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,12 @@ describe('Extension entry point', () => {
await activate(mockExtensionContext);

expect(mockWorkspace.createFileSystemWatcher).toHaveBeenCalledTimes(2);
expect(mockWorkspace.createFileSystemWatcher.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"**/.stylelintrc{,.js,.json,.yaml,.yml}",
]
`);
expect(mockWorkspace.createFileSystemWatcher.mock.calls[1]).toMatchInlineSnapshot(`
Array [
"**/{stylelint.config.js,.stylelintignore}",
]
`);
expect(mockWorkspace.createFileSystemWatcher.mock.calls[0]).toEqual([
'**/.stylelintrc{,.js,.json,.yaml,.yml}',
]);
expect(mockWorkspace.createFileSystemWatcher.mock.calls[1]).toEqual([
'**/{stylelint.config.js,.stylelintignore}',
]);
});

it('should register an auto-fix command', async () => {
Expand All @@ -138,12 +134,10 @@ describe('Extension entry point', () => {

expect(mockCommands.registerCommand).toHaveBeenCalled();
// cspell:disable
expect(mockCommands.registerCommand.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"stylelint.executeAutofix",
[Function],
]
`);
expect(mockCommands.registerCommand.mock.calls[0]).toMatchObject([
'stylelint.executeAutofix',
expect.any(Function),
]);
// cspell:enable
expect(subscriptions).toContain(disposable);
});
Expand Down Expand Up @@ -182,11 +176,9 @@ describe('Extension entry point', () => {

expect(sendRequest).toHaveBeenCalledTimes(1);
expect(mockWindow.showErrorMessage).toHaveBeenCalledTimes(1);
expect(mockWindow.showErrorMessage.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"Failed to apply Stylelint fixes to the document. Please consider opening an issue with steps to reproduce.",
]
`);
expect(mockWindow.showErrorMessage.mock.calls[0]).toEqual([
'Failed to apply Stylelint fixes to the document. Please consider opening an issue with steps to reproduce.',
]);
});

it('should register a restart server command', async () => {
Expand All @@ -199,12 +191,10 @@ describe('Extension entry point', () => {
const { subscriptions } = mockExtensionContext;

expect(mockCommands.registerCommand).toHaveBeenCalled();
expect(mockCommands.registerCommand.mock.calls[1]).toMatchInlineSnapshot(`
Array [
"stylelint.restart",
[Function],
]
`);
expect(mockCommands.registerCommand.mock.calls[1]).toMatchObject([
'stylelint.restart',
expect.any(Function),
]);
expect(subscriptions).toContain(disposable);
});

Expand Down Expand Up @@ -332,16 +322,8 @@ describe('Extension entry point', () => {
await new Promise((resolve) => setImmediate(resolve));

expect(mockWindow.showErrorMessage).toHaveBeenCalledTimes(2);
expect(mockWindow.showErrorMessage.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"Stylelint: Problem!",
]
`);
expect(mockWindow.showErrorMessage.mock.calls[1]).toMatchInlineSnapshot(`
Array [
"Stylelint: String problem!",
]
`);
expect(mockWindow.showErrorMessage.mock.calls[0]).toEqual(['Stylelint: Problem!']);
expect(mockWindow.showErrorMessage.mock.calls[1]).toEqual(['Stylelint: String problem!']);
});

it('should show an error message if restarting the language server fails', async () => {
Expand All @@ -362,16 +344,8 @@ describe('Extension entry point', () => {
await mockCommands.registerCommand.mock.calls[1][1]();

expect(mockWindow.showErrorMessage).toHaveBeenCalledTimes(2);
expect(mockWindow.showErrorMessage.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"Stylelint: Problem!",
]
`);
expect(mockWindow.showErrorMessage.mock.calls[1]).toMatchInlineSnapshot(`
Array [
"Stylelint: String problem!",
]
`);
expect(mockWindow.showErrorMessage.mock.calls[0]).toEqual(['Stylelint: Problem!']);
expect(mockWindow.showErrorMessage.mock.calls[1]).toEqual(['Stylelint: String problem!']);
});

it('should stop language client on deactivate', async () => {
Expand Down
Loading

0 comments on commit 393534e

Please sign in to comment.