Skip to content

Commit

Permalink
chore: e2e (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
bisquit authored Jul 13, 2023
1 parent cb28f1f commit febfd9f
Show file tree
Hide file tree
Showing 18 changed files with 4,275 additions and 234 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: E2E

on:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'pnpm'

- name: install
run: pnpm i

- name: build
run: pnpm build

- name: restore vscode
id: cache-vscode-restore
uses: actions/cache/restore@v3
with:
path: |
./e2e/.wdio-vscode-service
key: ${{ runner.os }}-vscode-1.80.0

- name: e2e
uses: coactions/setup-xvfb@v1
with:
run: pnpm e2e

- name: cache vscode
id: cache-vscode
uses: actions/cache/save@v3
with:
path: |
./e2e/.wdio-vscode-service
key: ${{ steps.cache-vscode-restore.outputs.cache-primary-key }}
5 changes: 5 additions & 0 deletions CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ pnpm test
pnpm validate
```

```sh
# e2e
pnpm e2e
```

## PR

Use `czg` or make sure to prefix type.
Expand Down
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.wdio-vscode-service
1 change: 1 addition & 0 deletions e2e/fixtures/folders/a/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Empty file added e2e/fixtures/folders/a/a.txt
Empty file.
12 changes: 12 additions & 0 deletions e2e/fixtures/workspaces/multiroot-configured.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"folders": [
{
"path": "../folders/a"
}
],
"settings": {
"workbench.colorCustomizations": {
"titleBar.activeBackground": "#000000"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "../folders/a"
}
],
"settings": {}
}
18 changes: 18 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "e2e",
"scripts": {
"wdio": "wdio run ./wdio.conf.ts"
},
"devDependencies": {
"@wdio/cli": "^8.12.2",
"@wdio/globals": "^8.12.1",
"@wdio/local-runner": "^8.12.1",
"@wdio/mocha-framework": "^8.12.1",
"@wdio/spec-reporter": "^8.12.2",
"@wdio/types": "^8.10.4",
"chromedriver": "^114.0.2",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"wdio-vscode-service": "^5.2.0"
}
}
36 changes: 36 additions & 0 deletions e2e/specs/multiroot-configured.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { browser } from '@wdio/globals';
import { TextEditor } from 'wdio-vscode-service';

import {
getBasenameFromPath,
openWorkspace,
resolveFixture,
snapshotFile,
} from './utils';

describe('multiroot', () => {
describe('configured', () => {
const workspaceFile = resolveFixture(
'workspaces/multiroot-configured.code-workspace',
);

snapshotFile(workspaceFile);

it('should not be colorized', async () => {
await openWorkspace(workspaceFile);

const workbench = await browser.getWorkbench();

await workbench.executeCommand('Open Workspace Configuration File');
const textEditor = (await workbench
.getEditorView()
.openEditor(getBasenameFromPath(workspaceFile))) as TextEditor;
const text = await textEditor.getText();

expect(text.includes('"titleBar.activeBackground": "#000000"')).toBe(
true,
);
expect(text.includes('"titleBar.activeForeground"')).toBe(false);
});
});
});
34 changes: 34 additions & 0 deletions e2e/specs/multiroot-not-configured.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { browser } from '@wdio/globals';
import { TextEditor } from 'wdio-vscode-service';

import {
getBasenameFromPath,
openWorkspace,
resolveFixture,
snapshotFile,
} from './utils';

describe('multi-root', () => {
describe('not configured', () => {
const workspaceFile = resolveFixture(
'workspaces/multiroot-not-configured.code-workspace',
);

snapshotFile(workspaceFile);

it('should be colorized', async () => {
await openWorkspace(workspaceFile);

const workbench = await browser.getWorkbench();

await workbench.executeCommand('Open Workspace Configuration File');
const textEditor = (await workbench
.getEditorView()
.openEditor(getBasenameFromPath(workspaceFile))) as TextEditor;
const text = await textEditor.getText();

expect(text.includes('"titleBar.activeBackground"')).toBe(true);
expect(text.includes('"titleBar.activeForeground"')).toBe(true);
});
});
});
28 changes: 28 additions & 0 deletions e2e/specs/singlefolder.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { browser } from '@wdio/globals';
import { TextEditor } from 'wdio-vscode-service';

import { openFolder, resolveFixture, snapshotFile } from './utils';

describe('singlefolder', () => {
const folder = resolveFixture('folders/a');

snapshotFile(resolveFixture('folders/a/.vscode/settings.json'));

it('should not be colorized', async () => {
await openFolder(folder);

const workbench = await browser.getWorkbench();

const inputBox = await workbench.executeCommand('Go to File');
await inputBox.setText('settings.json');
await inputBox.confirm();

const textEditor = (await workbench
.getEditorView()
.openEditor('settings.json')) as TextEditor;
const text = await textEditor.getText();

expect(text.includes('{}')).toBe(true);
expect(text.includes('"titleBar.activeBackground"')).toBe(false);
});
});
63 changes: 63 additions & 0 deletions e2e/specs/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { readFile, writeFile } from 'node:fs/promises';
import { basename, resolve } from 'node:path';

export function resolveFixture(pathFromFixture: string) {
return resolve(__dirname, '../fixtures', pathFromFixture);
}

export function getBasenameFromPath(path: string) {
return basename(path);
}

export function getWorkspaceNameFromPath(path: string) {
return basename(path, '.code-workspace');
}

export function snapshotFile(filePath: string) {
let originalContent: string;

before(async () => {
// store original content
const content = await readFile(filePath, {
encoding: 'utf-8',
});
originalContent = content;
});

after(async () => {
// reset content
if (originalContent) {
await writeFile(filePath, originalContent);
}
});
}

export async function openWorkspace(workspaceFile: string) {
await browser.executeWorkbench((vscode, workspaceFile) => {
vscode.commands.executeCommand(
'vscode.openFolder',
vscode.Uri.parse(workspaceFile),
);
}, workspaceFile);

const workspaceName = getWorkspaceNameFromPath(workspaceFile);
await browser.waitUntil(async () => {
const title = await (await browser.getWorkbench()).getTitleBar().getTitle();
return title.includes(workspaceName);
});
}

export async function openFolder(folder: string) {
await browser.executeWorkbench((vscode, folder) => {
vscode.commands.executeCommand(
'vscode.openFolder',
vscode.Uri.parse(folder),
);
}, folder);

const folderName = getBasenameFromPath(folder);
await browser.waitUntil(async () => {
const title = await (await browser.getWorkbench()).getTitleBar().getTitle();
return title.includes(folderName);
});
}
14 changes: 14 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"types": [
"@wdio/globals/types",
"@wdio/mocha-framework",
"expect-webdriverio",
"node",
"wdio-vscode-service"
],
"target": "es2022"
}
}
44 changes: 44 additions & 0 deletions e2e/wdio.conf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Options } from '@wdio/types';

import { resolve } from 'node:path';

// https://webdriver.io/docs/configurationfile/
export const config: Options.Testrunner = {
autoCompileOpts: {
autoCompile: true,
tsNodeOpts: {
project: './tsconfig.json',
transpileOnly: true,
},
},
bail: 0,
baseUrl: '',
capabilities: [
{
browserName: 'vscode',
browserVersion: '1.80.0',
'wdio:vscodeOptions': {
// specify extension path that includes `package.json`
extensionPath: resolve(__dirname, '..'),
},
},
],
connectionRetryCount: 3,
connectionRetryTimeout: 120000,
exclude: [],
framework: 'mocha',
// less info to more easily see spec result
logLevel: 'warn',
// avoid manipulation conflict
maxInstancesPerCapability: 1,
mochaOpts: {
timeout: 60000,
ui: 'bdd',
},
reporters: ['spec'],
runner: 'local',
services: ['vscode'],
// specify spec path
specs: ['./specs/**/*.e2e.ts'],
waitforTimeout: 10000,
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"publisher": "bisquit",
"icon": "assets/icon.png",
"engines": {
"vscode": "^1.79.2"
"vscode": "^1.80.0"
},
"categories": [],
"keywords": [
Expand Down Expand Up @@ -39,6 +39,7 @@
"test": "vitest",
"test:coverage": "vitest --coverage.enabled --coverage.provider=v8 --coverage.all --coverage.clean --coverage.include=src/utils",
"test:ci": "pnpm run test:coverage --run",
"e2e": "pnpm --filter e2e wdio",
"vsce:package": "pnpm vsce package --no-dependencies",
"vsce:publish": "pnpm vsce publish --no-dependencies"
},
Expand Down
Loading

0 comments on commit febfd9f

Please sign in to comment.