Skip to content

Commit b1d05cc

Browse files
committed
Add an e2e test for web and CI build step
1 parent 5752566 commit b1d05cc

File tree

9 files changed

+198
-131
lines changed

9 files changed

+198
-131
lines changed

.github/workflows/ci.yml

+35
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,38 @@ jobs:
7474
uses: GabrielBB/[email protected]
7575
with:
7676
run: yarn test --stream
77+
78+
webtest:
79+
name: Build and Test (web)
80+
# strategy:
81+
# matrix:
82+
# os: [macos-12, ubuntu-22.04, windows-2022]
83+
# runs-on: ${{ matrix.os }}
84+
runs-on: ubuntu-22.04
85+
# env:
86+
# OS: ${{ matrix.os }}
87+
timeout-minutes: 15
88+
steps:
89+
- uses: actions/checkout@v1
90+
- name: Setup Node
91+
uses: actions/setup-node@v3
92+
with:
93+
node-version: '18'
94+
- name: Restore Dependencies and VS Code test instance
95+
uses: actions/cache@v3
96+
with:
97+
path: |
98+
node_modules
99+
*/*/node_modules
100+
packages/foam-vscode/.vscode-test
101+
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', 'packages/foam-vscode/src/test/run-tests.ts') }}-${{ secrets.CACHE_VERSION }}
102+
- name: Install Dependencies
103+
run: yarn
104+
- name: Build Packages
105+
run: yarn build
106+
- name: Download required playwright browsers
107+
run: yarn playwright install
108+
- name: Run Tests
109+
uses: GabrielBB/[email protected]
110+
with:
111+
run: yarn test:web

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"clean": "lerna run clean",
1818
"build": "lerna run build",
1919
"test": "yarn workspace foam-vscode test --stream",
20+
"test:web": "yarn workspace foam-vscode test:web",
2021
"lint": "lerna run lint",
2122
"watch": "lerna run watch --concurrency 20 --stream"
2223
},

packages/foam-vscode/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@
657657
"test:unit": "node ./out/test/run-tests.js --unit",
658658
"pretest:e2e": "yarn build",
659659
"test:e2e": "node ./out/test/run-tests.js --e2e",
660+
"pretest:web": "tsc -p tsconfig.webTest.json && npm run compile-web",
661+
"test:web": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=out/web/test/web/index.js",
660662
"lint": "dts lint src",
661663
"clean": "rimraf out",
662664
"watch": "tsc --build ./tsconfig.json --watch",
@@ -679,7 +681,7 @@
679681
"@types/lodash": "^4.14.157",
680682
"@types/markdown-it": "^12.0.1",
681683
"@types/micromatch": "^4.0.1",
682-
"@types/mocha": "^10.0.2",
684+
"@types/mocha": "^10.0.6",
683685
"@types/node": "^13.13.52",
684686
"@types/picomatch": "^2.2.1",
685687
"@types/remove-markdown": "^0.1.1",
@@ -701,7 +703,7 @@
701703
"jest-extended": "^3.2.3",
702704
"markdown-it": "^12.0.4",
703705
"micromatch": "^4.0.2",
704-
"mocha": "^10.2.0",
706+
"mocha": "^10.3.0",
705707
"os-browserify": "^0.3.0",
706708
"path-browserify": "^1.0.1",
707709
"process": "^0.11.10",
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*global mocha:readonly*/
2+
/*global __WebpackModuleApi:readonly*/
3+
4+
// Imports mocha for the browser, defining the `mocha` global.
5+
require('mocha/mocha');
6+
7+
export function run(): Promise<void> {
8+
return new Promise((c, e) => {
9+
mocha.setup({
10+
ui: 'tdd',
11+
reporter: undefined,
12+
});
13+
14+
// Bundles all files in the current directory matching `*.test`
15+
const importAll = (r: __WebpackModuleApi.RequireContext) =>
16+
r.keys().forEach(r);
17+
importAll(require.context('.', true, /\.webtest$/));
18+
19+
try {
20+
// Run the mocha test
21+
mocha.run(failures => {
22+
if (failures > 0) {
23+
e(new Error(`${failures} tests failed.`));
24+
} else {
25+
c();
26+
}
27+
});
28+
} catch (err) {
29+
console.error(err);
30+
e(err);
31+
}
32+
});
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*global suite:readonly*/
2+
3+
import * as assert from 'assert';
4+
import * as vscode from 'vscode';
5+
suite('Foam Web Extension Test Suite', () => {
6+
vscode.window.showInformationMessage('Start all tests.');
7+
8+
test('Foam extension is loaded', () => {
9+
assert.ok(vscode.extensions.getExtension('foam.foam-vscode'));
10+
});
11+
});

packages/foam-vscode/src/web/features/preview/wikilink-embed.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*global markdownit:readonly*/
2+
13
import { ResourceParser } from 'packages/foam-vscode/src/core/model/note';
24
import { FoamWorkspace } from 'packages/foam-vscode/src/core/model/workspace';
35

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"compilerOptions": {
3-
"module": "commonjs",
43
"target": "ES2019",
54
"outDir": "./out/web",
65
"lib": ["ES2019"],
6+
"sourceMap": true,
77
"rootDir": "./src",
8-
"strict": true,
8+
"strict": true /* enable all strict type-checking options */,
99
"skipLibCheck": true
1010
},
11-
"include": ["./src/test/run-tests-web.ts"]
11+
"include": ["./src/test/web/index.ts"]
1212
}

packages/foam-vscode/web/webpack.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ const webExtensionConfig = {
5656
],
5757
},
5858
plugins: [
59+
new webpack.optimize.LimitChunkCountPlugin({
60+
maxChunks: 1, // disable chunks by default since web extensions must be a single bundle
61+
}),
5962
new webpack.ProvidePlugin({
6063
process: 'process/browser', // provide a shim for the global `process` variable
6164
}),
@@ -67,5 +70,8 @@ const webExtensionConfig = {
6770
hints: false,
6871
},
6972
devtool: 'nosources-source-map', // create a source map that points to the original source file
73+
infrastructureLogging: {
74+
level: 'log', // enables logging required for problem matchers
75+
},
7076
};
7177
module.exports = [webExtensionConfig];

0 commit comments

Comments
 (0)