Skip to content

Commit a849a6d

Browse files
committed
revamp testing
Signed-off-by: Karthik Ganeshram <kganeshr@akamai.com>
1 parent 489e641 commit a849a6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4368
-2006
lines changed

.github/workflows/test.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,37 @@ jobs:
4444
with:
4545
github_token: ${{ secrets.GITHUB_TOKEN }}
4646

47+
- name: Cache Docker images
48+
uses: actions/cache@v3
49+
with:
50+
path: /tmp/docker-images
51+
key: docker-${{ runner.os }}-postgres15-mysql8
52+
restore-keys: |
53+
docker-${{ runner.os }}-
54+
55+
- name: Load Docker images
56+
run: |
57+
if [ -f /tmp/docker-images/postgres.tar ]; then
58+
docker load -i /tmp/docker-images/postgres.tar
59+
fi
60+
if [ -f /tmp/docker-images/mysql.tar ]; then
61+
docker load -i /tmp/docker-images/mysql.tar
62+
fi
63+
4764
- name: Run Test
4865
shell: bash
4966
run: |
5067
cd test
51-
./test.sh
68+
npm run test
69+
70+
- name: Save Docker images
71+
if: always()
72+
run: |
73+
mkdir -p /tmp/docker-images
74+
docker pull postgres:15 2>/dev/null || true
75+
docker pull mysql:8.0 2>/dev/null || true
76+
docker save postgres:15 -o /tmp/docker-images/postgres.tar 2>/dev/null || true
77+
docker save mysql:8.0 -o /tmp/docker-images/mysql.tar 2>/dev/null || true
5278
5379
test_template:
5480
runs-on: ${{ matrix.os }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"private": true,
77
"scripts": {
88
"docs": "typedoc",
9-
"test": "cd test && ./test.sh"
9+
"test": "cd test && npm run test"
1010
},
1111
"repository": {
1212
"type": "git",
File renamed without changes.
File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "starlingmonkey",
6+
"request": "launch",
7+
"name": "Debug StarlingMonkey component",
8+
"component": "${workspaceFolder}/dist/chained-sourcemaps.wasm",
9+
"program": "${workspaceFolder}/src/index.ts",
10+
"stopOnEntry": false,
11+
"trace": true
12+
}
13+
]
14+
}

test/test-app/.vscode/settings.json renamed to test/apps/debugger-testing/chained-sourcemaps/.vscode/settings.json

File renamed without changes.

test/test-empty-precompile/README.md renamed to test/apps/debugger-testing/chained-sourcemaps/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# `http-js` Template
1+
# `http-ts` Template
22

3-
A starter template for building JavaScript HTTP applications with Spin.
3+
A starter template for building TypeScript HTTP applications with Spin.
44

55
## Getting Started
66

@@ -29,4 +29,11 @@ To use additional Spin interfaces, install the corresponding packages:
2929
| PostgreSQL | `@spinframework/spin-postgres` |
3030
| Redis | `@spinframework/spin-redis` |
3131
| SQLite | `@spinframework/spin-sqlite` |
32-
| Variables | `@spinframework/spin-variables` |
32+
| Variables | `@spinframework/spin-variables` |
33+
34+
## Using the StarlingMonkey Debugger for VS Code
35+
36+
1. First install the [StarlingMonkey Debugger](https://marketplace.visualstudio.com/items?itemName=BytecodeAlliance.starlingmonkey-debugger) extension.
37+
2. Build the component using the debug command `npm run build:debug`.
38+
3. Uncomment `tcp://127.0.0.1:*` in the `allowed_outbound_hosts` field in the `spin.toml`.
39+
4. Start the debugger in VS Code which should start Spin and attach the debugger. The debugger needs to be restarted for each http call.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// build.mjs
2+
import { build } from 'esbuild';
3+
import path from 'path';
4+
import { SpinEsbuildPlugin } from "@spinframework/build-tools/plugins/esbuild/index.js";
5+
import fs from 'fs';
6+
7+
const spinPlugin = await SpinEsbuildPlugin();
8+
9+
// plugin to handle vendor files in node_modules that may not be bundled.
10+
// Instead of generating a real source map for these files, it appends a minimal
11+
// inline source map pointing to an empty source. This avoids errors and ensures
12+
// source maps exist even for unbundled vendor code.
13+
let SourceMapPlugin = {
14+
name: 'excludeVendorFromSourceMap',
15+
setup(build) {
16+
build.onLoad({ filter: /node_modules/ }, args => {
17+
return {
18+
contents: fs.readFileSync(args.path, 'utf8')
19+
+ '\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
20+
loader: 'default',
21+
}
22+
})
23+
},
24+
}
25+
26+
await build({
27+
entryPoints: ['./src/index.ts'],
28+
outfile: './build/bundle.js',
29+
bundle: true,
30+
format: 'esm',
31+
platform: 'node',
32+
sourcemap: true,
33+
minify: false,
34+
plugins: [spinPlugin, SourceMapPlugin],
35+
logLevel: 'error',
36+
loader: {
37+
'.ts': 'ts',
38+
'.tsx': 'tsx',
39+
},
40+
resolveExtensions: ['.ts', '.tsx', '.js'],
41+
sourceRoot: path.resolve(process.cwd(), 'src'),
42+
});

0 commit comments

Comments
 (0)