Skip to content

Commit

Permalink
refactor: project quality of life improvements (#254)
Browse files Browse the repository at this point in the history
* refactor: simplify asset link URI resolving

* refactor: simplify types in test utilities

* refactor: keep same `getWorkspaceUri` parameters as `vscode.Uri.joinPath`

* refactor: add types and simplufy `getWorkspaceUri` calls

* refactor: move extension properties to environment variables
  • Loading branch information
byCedric committed Mar 9, 2024
1 parent 8ef750e commit deeca27
Show file tree
Hide file tree
Showing 28 changed files with 169 additions and 149 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/commands/code-provider.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import * as jsonc from 'jsonc-parser';
import { commands, TextEditor, window } from 'vscode';
import vscode from 'vscode';

import { PreviewCommand, PreviewModProvider } from '../../preview/constants';
import {
Expand All @@ -13,11 +13,11 @@ import {
import { waitForFalse, waitForTrue } from '../utils/wait';

describe('CodeProvider', () => {
let app: TextEditor;
let app: vscode.TextEditor;
let restoreContent: ReturnType<typeof storeOriginalContent>;

before(async () => {
app = await window.showTextDocument(getWorkspaceUri('preview/app.json'));
app = await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json'));
restoreContent = storeOriginalContent(app);
});

Expand All @@ -27,7 +27,7 @@ describe('CodeProvider', () => {
});

it('updates preview on added and removed content', async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.androidManifest
);
Expand Down
19 changes: 14 additions & 5 deletions src/__tests__/commands/preview-config.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { expect } from 'chai';
import { commands, window } from 'vscode';
import vscode from 'vscode';

import { ExpoConfigType, PreviewCommand } from '../../preview/constants';
import { sanitizeSnapshotValues } from '../utils/snapshot';
import { closeAllEditors, getWorkspaceUri, waitForEditorOpen } from '../utils/vscode';

describe(PreviewCommand.OpenExpoConfigPrebuild, () => {
beforeEach(async () => {
await window.showTextDocument(getWorkspaceUri('preview/app.json'));
await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json'));
});

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

it(`runs for ${ExpoConfigType.INTROSPECT}`, async () => {
await commands.executeCommand(PreviewCommand.OpenExpoConfigPrebuild, ExpoConfigType.INTROSPECT);
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoConfigPrebuild,
ExpoConfigType.INTROSPECT
);

const preview = await waitForEditorOpen('_app.config.json');
expect(preview).to.exist;
Expand All @@ -25,7 +28,10 @@ describe(PreviewCommand.OpenExpoConfigPrebuild, () => {
});

it(`runs for ${ExpoConfigType.PREBUILD}`, async () => {
await commands.executeCommand(PreviewCommand.OpenExpoConfigPrebuild, ExpoConfigType.PREBUILD);
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoConfigPrebuild,
ExpoConfigType.PREBUILD
);

const preview = await waitForEditorOpen('_app.config.json');
expect(preview).to.exist;
Expand All @@ -35,7 +41,10 @@ describe(PreviewCommand.OpenExpoConfigPrebuild, () => {
});

it(`runs for ${ExpoConfigType.PUBLIC}`, async () => {
await commands.executeCommand(PreviewCommand.OpenExpoConfigPrebuild, ExpoConfigType.PUBLIC);
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoConfigPrebuild,
ExpoConfigType.PUBLIC
);

const preview = await waitForEditorOpen('exp.json');
expect(preview).to.exist;
Expand Down
24 changes: 12 additions & 12 deletions src/__tests__/commands/preview-modifier-json.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { expect } from 'chai';
import { commands, window } from 'vscode';
import vscode from 'vscode';

import { PreviewCommand, PreviewModProvider } from '../../preview/constants';
import { sanitizeSnapshotValues } from '../utils/snapshot';
import { closeAllEditors, getWorkspaceUri, waitForEditorOpen } from '../utils/vscode';

describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
beforeEach(async () => {
await window.showTextDocument(getWorkspaceUri('preview/app.json'));
await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json'));
});

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

it(`runs for ${PreviewModProvider.androidColors} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.androidColors
);
Expand All @@ -28,7 +28,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidColorsNight} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.androidColorsNight
);
Expand All @@ -41,7 +41,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidGradleProperties} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.androidGradleProperties
);
Expand All @@ -54,7 +54,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidManifest} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.androidManifest
);
Expand All @@ -67,7 +67,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidStrings} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.androidStrings
);
Expand All @@ -80,7 +80,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidStyles} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.androidStyles
);
Expand All @@ -93,7 +93,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
});

it(`runs for ${PreviewModProvider.iosEntitlements} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.iosEntitlements
);
Expand All @@ -106,7 +106,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
});

it(`runs for ${PreviewModProvider.iosExpoPlist} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.iosExpoPlist
);
Expand All @@ -119,7 +119,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
});

it(`runs for ${PreviewModProvider.iosInfoPlist} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.iosInfoPlist
);
Expand All @@ -132,7 +132,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => {
});

it(`runs for ${PreviewModProvider.iosPodfileProperties} in json format`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFileJsonPrebuild,
PreviewModProvider.iosPodfileProperties
);
Expand Down
36 changes: 18 additions & 18 deletions src/__tests__/commands/preview-modifier.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { expect } from 'chai';
import { commands, window } from 'vscode';
import vscode from 'vscode';

import { PreviewCommand, PreviewModProvider } from '../../preview/constants';
import { sanitizeSnapshotValues } from '../utils/snapshot';
import { closeAllEditors, getWorkspaceUri, waitForEditorOpen } from '../utils/vscode';

describe(PreviewCommand.OpenExpoFilePrebuild, () => {
beforeEach(async () => {
await window.showTextDocument(getWorkspaceUri('preview/app.json'));
await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json'));
});

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

it(`runs for ${PreviewModProvider.androidColors}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.androidColors
);
Expand All @@ -28,7 +28,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidColorsNight}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.androidColorsNight
);
Expand All @@ -41,7 +41,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidGradleProperties}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.androidGradleProperties
);
Expand All @@ -54,7 +54,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidManifest}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.androidManifest
);
Expand All @@ -67,7 +67,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidStrings}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.androidStrings
);
Expand All @@ -80,7 +80,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => {
});

it(`runs for ${PreviewModProvider.androidStyles}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.androidStyles
);
Expand All @@ -93,7 +93,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => {
});

it(`runs for ${PreviewModProvider.iosEntitlements}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.iosEntitlements
);
Expand All @@ -106,7 +106,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => {
});

it(`runs for ${PreviewModProvider.iosExpoPlist}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.iosExpoPlist
);
Expand All @@ -119,7 +119,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => {
});

it(`runs for ${PreviewModProvider.iosInfoPlist}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.iosInfoPlist
);
Expand All @@ -132,7 +132,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => {
});

it(`runs for ${PreviewModProvider.iosPodfileProperties}`, async () => {
await commands.executeCommand(
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.iosPodfileProperties
);
Expand All @@ -151,8 +151,8 @@ describe('dynamic configs', () => {
});

it(`runs ${PreviewModProvider.androidManifest} for app.json`, async () => {
await window.showTextDocument(getWorkspaceUri('preview/app.json'));
await commands.executeCommand(
await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json'));
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.androidManifest
);
Expand All @@ -165,8 +165,8 @@ describe('dynamic configs', () => {
});

it(`runs ${PreviewModProvider.iosInfoPlist} for app.config.js`, async () => {
await window.showTextDocument(getWorkspaceUri('preview-config-js/app.config.js'));
await commands.executeCommand(
await vscode.window.showTextDocument(getWorkspaceUri('preview-config-js', 'app.config.js'));
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.iosInfoPlist
);
Expand All @@ -179,8 +179,8 @@ describe('dynamic configs', () => {
});

it(`runs ${PreviewModProvider.androidManifest} for app.config.ts`, async () => {
await window.showTextDocument(getWorkspaceUri('preview-config-ts/app.config.ts'));
await commands.executeCommand(
await vscode.window.showTextDocument(getWorkspaceUri('preview-config-ts', 'app.config.ts'));
await vscode.commands.executeCommand(
PreviewCommand.OpenExpoFilePrebuild,
PreviewModProvider.androidManifest
);
Expand Down
4 changes: 1 addition & 3 deletions src/__tests__/extension.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { expect } from 'chai';
import { extensions } from 'vscode';

import { EXTENSION_ID } from './utils/vscode';

describe('extension', () => {
it('is activated', () => {
expect(extensions.getExtension(EXTENSION_ID)?.isActive).to.equal(true);
expect(extensions.getExtension(process.env.EXTENSION_ID)?.isActive).to.equal(true);
});
});
12 changes: 6 additions & 6 deletions src/__tests__/manifestAssetCompletions.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { expect } from 'chai';
import { commands, CompletionList, TextEditor, window } from 'vscode';
import vscode from 'vscode';

import { closeActiveEditor, findContentRange, getWorkspaceUri } from './utils/vscode';

describe('ManifestAssetCompletionsProvider', () => {
// Test for both app.json and app.config.json formats
['app.json', 'app.config.json'].forEach((manifestFile) => {
describe(`manifest: ${manifestFile}`, () => {
let app: TextEditor;
let app: vscode.TextEditor;

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

afterEach(() => closeActiveEditor());
Expand All @@ -19,7 +19,7 @@ describe('ManifestAssetCompletionsProvider', () => {
const range = findContentRange(app, './assets/icon.png');
await app.edit((builder) => builder.replace(range, './'));

const suggestions = await commands.executeCommand<CompletionList>(
const suggestions = await vscode.commands.executeCommand<vscode.CompletionList>(
'vscode.executeCompletionItemProvider',
app.document.uri,
range.start
Expand All @@ -34,7 +34,7 @@ describe('ManifestAssetCompletionsProvider', () => {
const range = findContentRange(app, './assets/icon.png');
await app.edit((builder) => builder.replace(range, './assets/'));

const suggestions = await commands.executeCommand<CompletionList>(
const suggestions = await vscode.commands.executeCommand<vscode.CompletionList>(
'vscode.executeCompletionItemProvider',
app.document.uri,
range.start
Expand All @@ -54,7 +54,7 @@ describe('ManifestAssetCompletionsProvider', () => {
const range = findContentRange(app, 'portrait');
await app.edit((builder) => builder.replace(range, './'));

const suggestions = await commands.executeCommand<CompletionList>(
const suggestions = await vscode.commands.executeCommand<vscode.CompletionList>(
'vscode.executeCompletionItemProvider',
app.document.uri,
range.start
Expand Down
Loading

0 comments on commit deeca27

Please sign in to comment.