Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate language-server tests to node:test #797

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions packages/language-server/test/check/check.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os from 'node:os';
import path from 'node:path';
import { expect } from 'chai';
import { before, describe, it } from 'mocha';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { AstroCheck, CheckResult } from '../../dist/check.js';

describe('AstroCheck', async () => {
let checker: AstroCheck;
let result: CheckResult;

before(async function () {
before(async function (this: any) {
// First init can sometimes be slow in CI, even though the rest of the tests will be fast.
this.timeout(50000);
checker = new AstroCheck(
Expand All @@ -20,33 +20,31 @@ describe('AstroCheck', async () => {
});

it('Can check files and return errors', async () => {
expect(result).to.not.be.undefined;
expect(result.fileResult).to.have.lengthOf(4);
assert.notEqual(result, undefined);
assert.equal(result.fileResult.length, 4);
});

it("Returns the file's URL", async () => {
expect(result.fileResult[0].fileUrl).to.not.be.undefined;
expect(result.fileResult[0].fileUrl instanceof URL).to.be.true;
assert.notEqual(result.fileResult[0].fileUrl, undefined);
assert.equal(result.fileResult[0].fileUrl instanceof URL, true);
});

it("Returns the file's content", async () => {
expect(result.fileResult[0].fileContent).to.not.be.undefined;
expect(result.fileResult[0].fileContent).to.deep.equal(
`---${os.EOL}console.log(doesntExist);${os.EOL}---${os.EOL}`
);
assert.notEqual(result.fileResult[0].fileContent, undefined);
assert.deepEqual(result.fileResult[0].fileContent, `---${os.EOL}console.log(doesntExist);${os.EOL}---${os.EOL}`);
});

it('Can return the total amount of errors, warnings and hints', async () => {
expect(result.errors).to.equal(2);
expect(result.warnings).to.equal(1);
expect(result.hints).to.equal(1);
assert.equal(result.errors, 2);
assert.equal(result.warnings, 1);
assert.equal(result.hints, 1);
});

it('Can return the total amount of files checked', async () => {
expect(result.fileChecked).to.equal(6);
assert.equal(result.fileChecked, 6);
});

it('Can return the status of the check', async () => {
expect(result.status).to.equal('completed');
assert.equal(result.status, 'completed');
});
});
12 changes: 6 additions & 6 deletions packages/language-server/test/css/completions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Position } from '@volar/language-server';
import { expect } from 'chai';
import { describe } from 'mocha';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { LanguageServer, getLanguageServer } from '../server.js';

describe('CSS - Completions', () => {
Expand All @@ -15,7 +15,7 @@ describe('CSS - Completions', () => {
Position.create(0, 18)
);

expect(completions!.items).to.not.be.empty;
assert.notEqual(completions!.items, '');
});

it('Can provide completions for CSS values', async () => {
Expand All @@ -28,7 +28,7 @@ describe('CSS - Completions', () => {
Position.create(0, 21)
);

expect(completions!.items).to.not.be.empty;
assert.notEqual(completions!.items, '');
});

it('Can provide completions inside inline styles', async () => {
Expand All @@ -38,7 +38,7 @@ describe('CSS - Completions', () => {
Position.create(0, 18)
);

expect(completions!.items).to.not.be.empty;
expect(completions?.items.map((i) => i.label)).to.include('aliceblue');
assert.notEqual(completions!.items, '');
assert.equal(completions?.items.map((i) => i.label).includes('aliceblue'), true);
});
});
6 changes: 3 additions & 3 deletions packages/language-server/test/css/hover.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Position } from '@volar/language-server';
import { expect } from 'chai';
import { describe } from 'mocha';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { LanguageServer, getLanguageServer } from '../server.js';

describe('CSS - Hover', () => {
Expand All @@ -17,6 +17,6 @@ describe('CSS - Hover', () => {
);
const hover = await languageServer.handle.sendHoverRequest(document.uri, Position.create(2, 7));

expect(hover?.contents).to.not.be.empty;
assert.notEqual(hover?.contents, '');
});
});
12 changes: 6 additions & 6 deletions packages/language-server/test/html/completions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Position } from '@volar/language-server';
import { expect } from 'chai';
import { describe } from 'mocha';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { type LanguageServer, getLanguageServer } from '../server.js';

describe('HTML - Completions', () => {
Expand All @@ -15,8 +15,8 @@ describe('HTML - Completions', () => {
Position.create(0, 2)
);

expect(completions!.items).to.not.be.empty;
expect(completions!.items[0].label).to.equal('blockquote');
assert.notEqual(completions!.items, '');
assert.equal(completions!.items[0].label, 'blockquote');
});

it('Can provide completions for HTML attributes', async () => {
Expand All @@ -26,7 +26,7 @@ describe('HTML - Completions', () => {
Position.create(0, 13)
);

expect(completions!.items).to.not.be.empty;
expect(completions!.items[0].label).to.equal('cite');
assert.notEqual(completions!.items, '');
assert.equal(completions!.items[0].label, 'cite');
});
});
8 changes: 4 additions & 4 deletions packages/language-server/test/html/hover.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Position } from '@volar/language-server';
import { expect } from 'chai';
import { describe } from 'mocha';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { type LanguageServer, getLanguageServer } from '../server.js';

describe('HTML - Hover', () => {
Expand All @@ -12,7 +12,7 @@ describe('HTML - Hover', () => {
const document = await languageServer.openFakeDocument(`<q`, 'astro');
const hover = await languageServer.handle.sendHoverRequest(document.uri, Position.create(0, 2));

expect(hover).to.not.be.null;
assert.notEqual(hover, null);
});

it('Can provide hover for HTML attributes', async () => {
Expand All @@ -22,6 +22,6 @@ describe('HTML - Hover', () => {
Position.create(0, 13)
);

expect(hover).to.not.be.null;
assert.notEqual(hover, null);
});
});
6 changes: 3 additions & 3 deletions packages/language-server/test/misc/format.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Range } from '@volar/language-server';
import { expect } from 'chai';
import { describe } from 'mocha';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { type LanguageServer, getLanguageServer } from '../server.js';

describe('Formatting', () => {
Expand All @@ -15,7 +15,7 @@ describe('Formatting', () => {
insertSpaces: true,
});

expect(formatEdits).to.deep.equal([
assert.deepEqual(formatEdits, [
{
range: Range.create(0, 0, 3, 3),
newText: '---\n\n---\n',
Expand Down
10 changes: 5 additions & 5 deletions packages/language-server/test/misc/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import type { InitializeResult, ServerCapabilities } from '@volar/language-server';
import { expect } from 'chai';
import { before, describe, it } from 'mocha';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { getLanguageServer } from '../server.js';

describe('Initialize', async () => {
let initializeResult: InitializeResult;

before(async function () {
before(async function (this: any) {
// First init can sometimes be slow in CI, even though the rest of the tests will be fast.
this.timeout(50000);
initializeResult = (await getLanguageServer()).initializeResult;
});

it('Can start server', async () => {
expect(initializeResult).not.be.null;
assert.notEqual(initializeResult, null);
});

it('Has proper capabilities', async () => {
Expand Down Expand Up @@ -143,6 +143,6 @@ describe('Initialize', async () => {
workspaceSymbolProvider: true,
};

expect(initializeResult.capabilities).to.deep.equal(capabilities);
assert.deepEqual(initializeResult.capabilities, capabilities);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Position } from '@volar/language-server';
import { expect } from 'chai';
import { before, describe, it } from 'mocha';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { type LanguageServer, getLanguageServer } from '../server.js';

describe('TypeScript Addons - Completions', async () => {
Expand All @@ -16,6 +16,6 @@ describe('TypeScript Addons - Completions', async () => {
);

const prerenderCompletions = completions?.items.filter((item) => item.label === 'prerender');
expect(prerenderCompletions).to.not.be.empty;
assert.notEqual(prerenderCompletions, '');
});
});
14 changes: 7 additions & 7 deletions packages/language-server/test/typescript/completions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Position } from '@volar/language-server';
import { expect } from 'chai';
import { before, describe, it } from 'mocha';
import assert from 'node:assert/strict';
import { after, describe, before, it } from 'node:test';
import { type LanguageServer, getLanguageServer } from '../server.js';

describe('TypeScript - Completions', async () => {
Expand All @@ -15,7 +15,7 @@ describe('TypeScript - Completions', async () => {
Position.create(1, 1)
);

expect(completions?.items).to.not.be.empty;
assert.notEqual(completions?.items, '');
});

it('Can get completions in the template', async () => {
Expand All @@ -25,7 +25,7 @@ describe('TypeScript - Completions', async () => {
Position.create(0, 1)
);

expect(completions?.items).to.not.be.empty;
assert.notEqual(completions?.items, '');
});

it('sort completions starting with `astro:` higher than other imports', async () => {
Expand All @@ -39,7 +39,7 @@ describe('TypeScript - Completions', async () => {
(item) => item.labelDetails?.description === 'astro:assets'
);

expect(imageCompletion?.sortText).to.equal('\x00￿16');
assert.equal(imageCompletion?.sortText, '\x00￿16');
});

it('Can get completions in all kinds of script tags', async () => {
Expand All @@ -57,8 +57,8 @@ describe('TypeScript - Completions', async () => {
);

const allLabels = completions?.items.map((item) => item.label);
expect(completions?.items).to.not.be.empty;
expect(allLabels).to.include('log');
assert.notEqual(completions?.items, '');
assert.equal(allLabels.includes('log'), true);
}
});
});
18 changes: 9 additions & 9 deletions packages/language-server/test/typescript/diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
FullDocumentDiagnosticReport,
Range,
} from '@volar/language-server';
import { expect } from 'chai';
import { before, describe, it } from 'mocha';
import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import { type LanguageServer, getLanguageServer } from '../server.js';

describe('TypeScript - Diagnostics', async () => {
Expand All @@ -21,12 +21,12 @@ describe('TypeScript - Diagnostics', async () => {
)) as FullDocumentDiagnosticReport;

// We should only have one error here.
expect(diagnostics.items).length(1);
assert.equal(diagnostics.items.length, 1);

// Data here is Volar specific, and is not too relevant to test. We'll throw it out.
const diagnostic: Diagnostic = { ...diagnostics.items[0], data: {} };

expect(diagnostic).to.deep.equal({
assert.deepEqual(diagnostic, {
code: 2304,
data: {},
message: "Cannot find name 'NotAThing'.",
Expand All @@ -41,10 +41,10 @@ describe('TypeScript - Diagnostics', async () => {
const diagnostics = (await languageServer.handle.sendDocumentDiagnosticRequest(
document.uri
)) as FullDocumentDiagnosticReport;
expect(diagnostics.items).length(1);
assert.equal(diagnostics.items.length, 1);

const diagnostic: Diagnostic = { ...diagnostics.items[0], data: {} };
expect(diagnostic).to.deep.equal({
assert.deepEqual(diagnostic, {
code: 2304,
data: {},
message: "Cannot find name 'nope'.",
Expand All @@ -62,10 +62,10 @@ describe('TypeScript - Diagnostics', async () => {
const diagnostics = (await languageServer.handle.sendDocumentDiagnosticRequest(
document.uri
)) as FullDocumentDiagnosticReport;
expect(diagnostics.items).length(1);
assert.equal(diagnostics.items.length, 1);

diagnostics.items = diagnostics.items.map((diag) => ({ ...diag, data: {} }));
expect(diagnostics.items).to.deep.equal([
assert.deepEqual(diagnostics.items, [
{
code: 2322,
data: {},
Expand All @@ -86,6 +86,6 @@ describe('TypeScript - Diagnostics', async () => {
const diagnostics = (await languageServer.handle.sendDocumentDiagnosticRequest(
document.uri
)) as FullDocumentDiagnosticReport;
expect(diagnostics.items).length(1);
assert.equal(diagnostics.items.length, 1);
});
});
16 changes: 8 additions & 8 deletions packages/language-server/test/units/parseAstro.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { getAstroMetadata } from '../../src/core/parseAstro.js';
import { createCompilerPoint, createCompilerPosition } from '../utils.js';

Expand All @@ -8,7 +8,7 @@ describe('parseAstro - Can parse astro files', () => {
const input = `---\n--- <div>Astro!</div>`;
const metadata = getAstroMetadata('file.astro', input);

expect(metadata.ast).to.deep.equal({
assert.deepEqual(metadata.ast, {
children: [
{
position: createCompilerPosition(
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('parseAstro - Can parse astro files', () => {
],
type: 'root',
});
expect(metadata.frontmatter).to.deep.equal({
assert.deepEqual(metadata.frontmatter, {
status: 'closed',
position: {
start: {
Expand All @@ -55,17 +55,17 @@ describe('parseAstro - Can parse astro files', () => {
},
},
});
expect(metadata.diagnostics).to.deep.equal([]);
assert.deepEqual(metadata.diagnostics, []);
});

it('properly return frontmatter states', () => {
const inputClosed = `---\n--- <div>Astro!</div>`;
expect(getAstroMetadata('file.astro', inputClosed).frontmatter.status).to.equal('closed');
assert.equal(getAstroMetadata('file.astro', inputClosed).frontmatter.status, 'closed');

const inputOpen = `---\n<div>Astro!</div>`;
expect(getAstroMetadata('file.astro', inputOpen).frontmatter.status).to.equal('open');
assert.equal(getAstroMetadata('file.astro', inputOpen).frontmatter.status, 'open');

const inputNull = `<div>Astro!</div>`;
expect(getAstroMetadata('file.astro', inputNull).frontmatter.status).to.equal('doesnt-exist');
assert.equal(getAstroMetadata('file.astro', inputNull).frontmatter.status, 'doesnt-exist');
});
});
Loading
Loading