Skip to content

Commit

Permalink
feature: diagnose manifest with dirty or changed documents (#225)
Browse files Browse the repository at this point in the history
* feature: add `debounce` utility function

* feature: add `debouncedDiagnose` function to diagnostics providers

* chore: only remove timeout on debounce

* refactor: update tests to avoid writing file to disk

* chore: remove `restoreOriginalContent` from test utilities

* Revert "chore: remove `restoreOriginalContent` from test utilities"

This reverts commit 1597311.
  • Loading branch information
byCedric committed Sep 4, 2023
1 parent 8eda594 commit 82c8dd3
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 31 deletions.
137 changes: 137 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@types/mocha": "^10.0.1",
"@types/node": "^18.17.12",
"@types/node-fetch": "^2.6.2",
"@types/sinon": "^10.0.16",
"@types/vscode": "^1.78.2",
"@vscode/test-electron": "^2.3.2",
"@vscode/vsce": "^2.21.0",
Expand All @@ -81,6 +82,7 @@
"raw-loader": "^4.0.2",
"semantic-release": "^21.1.1",
"semver": "^7.5.2",
"sinon": "^15.2.0",
"sucrase": "^3.20.3",
"typescript": "^5.2.2",
"webpack": "^5.76.0",
Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/manifestAssetCompletions.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ describe('ManifestAssetCompletionsProvider', () => {
app = await window.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`));
});

afterEach(async () => {
await closeActiveEditor();
});
afterEach(() => closeActiveEditor());

it('suggests folders from project', async () => {
const range = findContentRange(app, './assets/icon.png');
Expand Down
42 changes: 22 additions & 20 deletions src/__tests__/manifestDiagnostics.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import fs from 'fs';
import path from 'path';
import { DiagnosticSeverity, languages, TextEditor, window } from 'vscode';

import { findContentRange, getWorkspaceUri, storeOriginalContent } from './utils/vscode';
import {
closeAllEditors,
findContentRange,
getWorkspaceUri,
replaceEditorContent,
} from './utils/vscode';
import { waitFor } from './utils/wait';

describe('ManifestDiagnosticsProvider', () => {
Expand All @@ -13,23 +18,26 @@ describe('ManifestDiagnosticsProvider', () => {
['app.json', 'app.config.json'].forEach((manifestFile) => {
describe(`manifest: ${manifestFile}`, () => {
let app: TextEditor;
let restoreContent: ReturnType<typeof storeOriginalContent>;
let content: string;

before(async () => {
app = await window.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`));
restoreContent = storeOriginalContent(app);
content = await window
.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`))
.then((editor) => editor.document.getText());
});

afterEach(async () => {
await restoreContent();
beforeEach(async () => {
app = await window.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`));
});

afterEach(() => replaceEditorContent(app, content));
after(() => closeAllEditors());

it('diagnoses non-existing asset file reference', async () => {
const range = findContentRange(app, './assets/splash.png');
await app.edit((builder) => builder.replace(range, './assets/doesnt-exist.png'));
await app.document.save();
await waitFor(1000);

await waitFor();
const diagnostics = await languages.getDiagnostics(app.document.uri);

expect(diagnostics).to.have.length(1);
Expand All @@ -43,9 +51,8 @@ describe('ManifestDiagnosticsProvider', () => {
it('diagnoses asset directory reference', async () => {
const range = findContentRange(app, './assets/adaptive-icon.png');
await app.edit((builder) => builder.replace(range, './assets'));
await app.document.save();
await waitFor(1000);

await waitFor();
const diagnostics = await languages.getDiagnostics(app.document.uri);

expect(diagnostics).to.have.length(1);
Expand All @@ -59,9 +66,8 @@ describe('ManifestDiagnosticsProvider', () => {
it('diagnoses non-existing plugin definition', async () => {
const range = findContentRange(app, '"expo-system-ui",');
await app.edit((builder) => builder.replace(range, '"doesnt-exists",'));
await app.document.save();
await waitFor(1000);

await waitFor();
const diagnostics = await languages.getDiagnostics(app.document.uri);

expect(diagnostics).to.have.length(1);
Expand All @@ -75,9 +81,8 @@ describe('ManifestDiagnosticsProvider', () => {
it('diagnoses empty string plugin definition', async () => {
const range = findContentRange(app, '"plugins": [');
await app.edit((builder) => builder.replace(range, `"plugins": ["",`));
await app.document.save();
await waitFor(1000);

await waitFor();
const diagnostics = await languages.getDiagnostics(app.document.uri);

expect(diagnostics).to.have.length(1);
Expand All @@ -91,9 +96,8 @@ describe('ManifestDiagnosticsProvider', () => {
it('diagnoses empty array plugin definition', async () => {
const range = findContentRange(app, '"plugins": [');
await app.edit((builder) => builder.replace(range, `"plugins": [[],`));
await app.document.save();
await waitFor(1000);

await waitFor();
const diagnostics = await languages.getDiagnostics(app.document.uri);

expect(diagnostics).to.have.length(1);
Expand All @@ -119,9 +123,8 @@ describe('ManifestDiagnosticsProvider', () => {

const preRange = findContentRange(app, '"expo-system-ui",');
await app.edit((builder) => builder.replace(preRange, `"./${pluginName}",`));
await app.document.save();
await waitFor(1000);

await waitFor();
const preInstallDiagnostic = await languages.getDiagnostics(app.document.uri);

expect(preInstallDiagnostic).to.have.length(1);
Expand All @@ -142,9 +145,8 @@ describe('ManifestDiagnosticsProvider', () => {
await app.edit((builder) =>
builder.replace(findContentRange(app, `"./${pluginName}",`), `"./${pluginName}" ,`)
);
await app.document.save();
await waitFor(1000);

await waitFor();
const postInstallDiagnostic = await languages.getDiagnostics(app.document.uri);
expect(postInstallDiagnostic).to.have.length(0);

Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/manifestLinks.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ describe('ManifestLinksProvider', () => {
app = await window.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`));
});

afterEach(async () => {
await closeAllEditors();
});
afterEach(() => closeAllEditors());

describe('assets', () => {
it('opens valid asset link', async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/manifestPluginCompletions.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ describe('ManifestPluginCompletionsProvider', () => {
app = await window.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`));
});

afterEach(async () => {
await closeActiveEditor();
});
afterEach(() => closeActiveEditor());

it('suggests plugins from installed packages', async () => {
const range = findContentRange(app, 'expo-system-ui');
Expand Down
Loading

0 comments on commit 82c8dd3

Please sign in to comment.