Skip to content

Commit 15fab70

Browse files
authored
Merge pull request #320 from smocker-dev/chore/modernize-2026
Modernize Smocker to a 2026 stack (mock format & API preserved)
2 parents 5b70e8d + 5274d5e commit 15fab70

99 files changed

Lines changed: 12141 additions & 12407 deletions

File tree

Some content is hidden

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

.eslintignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

.eslintrc.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ jobs:
2525
- uses: actions/setup-node@v4
2626
with:
2727
node-version-file: .nvmrc
28-
cache: yarn
28+
cache: npm
2929

30-
- run: yarn install --frozen-lockfile
30+
- run: npm ci
3131

3232
- name: Lint sources
3333
run: |
3434
make lint
35-
yarn lint
35+
npm run lint
3636
3737
test:
3838
runs-on: ubuntu-latest
@@ -45,21 +45,21 @@ jobs:
4545
- uses: actions/setup-node@v4
4646
with:
4747
node-version-file: .nvmrc
48-
cache: yarn
48+
cache: npm
4949

5050

5151
- name: Setup Go environment
5252
uses: actions/setup-go@v5
5353
with:
5454
go-version: stable
5555

56-
- run: yarn install --frozen-lockfile
56+
- run: npm ci
5757

5858
- name: Execute tests
5959
run: |
6060
make test
6161
make test-integration
62-
yarn test
62+
npm test
6363
make coverage
6464
6565
- name: SonarCloud Scan
@@ -76,19 +76,19 @@ jobs:
7676
- uses: actions/checkout@v4
7777

7878
- id: extract_ref
79-
run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/})
79+
run: echo "GIT_REF=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT"
8080

8181
- uses: actions/setup-node@v4
8282
with:
8383
node-version-file: .nvmrc
84-
cache: yarn
84+
cache: npm
8585

8686
- name: Setup Go environment
8787
uses: actions/setup-go@v5
8888
with:
8989
go-version: stable
9090

91-
- run: yarn install --frozen-lockfile
91+
- run: npm ci
9292

9393
- name: Build
9494
run: |
@@ -102,16 +102,40 @@ jobs:
102102
name: smocker-bin
103103
path: ./build/smocker.tar.gz
104104

105+
e2e:
106+
runs-on: ubuntu-latest
107+
timeout-minutes: 10
108+
steps:
109+
- uses: actions/checkout@v4
110+
111+
- uses: actions/setup-node@v4
112+
with:
113+
node-version-file: .nvmrc
114+
cache: npm
115+
116+
- name: Setup Go environment
117+
uses: actions/setup-go@v5
118+
with:
119+
go-version: stable
120+
121+
- run: npm ci
122+
123+
- name: Install Playwright browser
124+
run: npx playwright install --with-deps chromium
125+
126+
- name: Run Playwright non-regression suite
127+
run: make test-e2e
128+
105129
deploy:
106-
needs: [lint, test, build]
130+
needs: [lint, test, build, e2e]
107131
if: startsWith(github.ref, 'refs/tags/')
108132
runs-on: ubuntu-latest
109133
timeout-minutes: 10
110134
steps:
111135
- uses: actions/checkout@v4
112136

113137
- id: extract_ref
114-
run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/})
138+
run: echo "GIT_REF=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT"
115139

116140
- uses: actions/download-artifact@v4
117141
with:

.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
.DS_Store
2-
.parcel-cache/
32
.vscode/
4-
build/
5-
coverage/
63
node_modules/
7-
sessions
8-
!tests/sessions
9-
smocker
10-
smocker.test
11-
yarn-error.log
4+
# All build, test and runtime output goes here (see Makefile / vite.config.ts / playwright.config.ts).
5+
build/

.golangci.yml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
1-
linters-settings:
2-
lll:
3-
line-length: 150
1+
version: "2"
42

5-
issues:
6-
exclude-rules:
7-
- text: "exported type .* should have comment or be unexported"
8-
linters:
9-
- go-lint
3+
linters:
4+
default: standard # errcheck, govet, ineffassign, staticcheck, unused
5+
enable:
6+
- lll
7+
- misspell
8+
settings:
9+
lll:
10+
line-length: 150
11+
staticcheck:
12+
checks:
13+
- all
14+
# ST1005: error strings should not be capitalized. Several validation errors are
15+
# returned verbatim over the API (e.g. mock validation messages), so their exact,
16+
# historically-capitalized wording is part of the observable contract and must not change.
17+
- -ST1005
18+
# ST1003 / ST1012: identifier naming conventions (e.g. Json vs JSON, ErrFoo error vars).
19+
# These are long-standing internal identifiers; renaming them is pure churn with no
20+
# effect on the mock format or HTTP API, so the existing names are kept for stability.
21+
- -ST1003
22+
- -ST1012
23+
exclusions:
24+
generated: lax
25+
paths:
26+
# node_modules ships a stray flatted/*.go; build is generated output. Neither is our code.
27+
- node_modules
28+
- build
29+
presets:
30+
- comments
31+
- std-error-handling
32+
33+
formatters:
34+
enable:
35+
- gofmt
36+
- goimports

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16
1+
24

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG GO_VERSION=1.22
1+
ARG GO_VERSION=1.26
22
FROM golang:${GO_VERSION}-alpine AS build-backend
33
RUN apk add --no-cache make
44
ARG VERSION=snapshot

Makefile

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ REFLEX=$(GOPATH)/bin/reflex
3434
$(REFLEX):
3535
go install github.com/cespare/reflex@latest
3636

37-
GOLANGCILINTVERSION:=1.64.8
37+
GOLANGCILINTVERSION:=2.12.2
3838
GOLANGCILINT=$(GOPATH)/bin/golangci-lint
3939
$(GOLANGCILINT):
40-
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v$(GOLANGCILINTVERSION)
40+
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/v$(GOLANGCILINTVERSION)/install.sh | sh -s -- -b $(GOPATH)/bin v$(GOLANGCILINTVERSION)
4141

4242
VENOMVERSION:=v1.0.0-rc.6
4343
VENOM=$(GOPATH)/bin/venom
@@ -48,22 +48,29 @@ GOCOVMERGE=$(GOPATH)/bin/gocovmerge
4848
$(GOCOVMERGE):
4949
go install github.com/wadey/gocovmerge@latest
5050

51+
CADDYVERSION:=v2.8.4
5152
CADDY=$(GOPATH)/bin/caddy
5253
$(CADDY):
53-
cd /tmp; go get github.com/caddyserver/caddy/v2/...
54+
go install github.com/caddyserver/caddy/v2/cmd/caddy@$(CADDYVERSION)
55+
56+
# All generated/runtime artifacts live under build/ so the repository root stays clean.
57+
BUILD_DIR=build
58+
SESSIONS_DIR=$(BUILD_DIR)/sessions
59+
COVERAGE_DIR=$(BUILD_DIR)/coverage
5460

5561
.PHONY: persistence
5662
persistence:
57-
rm -rf ./sessions || true
58-
cp -r tests/sessions sessions
63+
rm -rf ./$(SESSIONS_DIR) || true
64+
mkdir -p $(BUILD_DIR)
65+
cp -r tests/sessions $(SESSIONS_DIR)
5966

6067
.PHONY: start
6168
start: $(REFLEX) persistence
6269
$(REFLEX) --start-service \
6370
--decoration='none' \
6471
--regex='\.go$$' \
6572
--inverse-regex='^vendor|node_modules|.cache/' \
66-
-- go run $(GO_LDFLAGS) main.go --log-level=$(LEVEL) --static-files ./build/client --persistence-directory ./sessions
73+
-- go run $(GO_LDFLAGS) main.go --log-level=$(LEVEL) --static-files ./build/client --persistence-directory ./$(SESSIONS_DIR)
6774

6875
.PHONY: build
6976
build:
@@ -79,15 +86,15 @@ format:
7986

8087
.PHONY: test
8188
test:
82-
mkdir -p coverage
83-
go test -v -race -coverprofile=coverage/test-cover.out ./server/...
89+
mkdir -p $(COVERAGE_DIR)
90+
go test -v -race -coverprofile=$(COVERAGE_DIR)/test-cover.out ./server/...
8491

8592
PID_FILE=/tmp/$(APPNAME).test.pid
8693
.PHONY: test-integration
8794
test-integration: $(VENOM) check-default-ports persistence
88-
mkdir -p coverage
89-
go test -race -coverpkg="./..." -c . -o $(APPNAME).test
90-
SMOCKER_PERSISTENCE_DIRECTORY=./sessions ./$(APPNAME).test -test.coverprofile=coverage/test-integration-cover.out >/dev/null 2>&1 & echo $$! > $(PID_FILE)
95+
mkdir -p $(COVERAGE_DIR)
96+
go test -race -coverpkg="./..." -c . -o $(BUILD_DIR)/$(APPNAME).test
97+
SMOCKER_PERSISTENCE_DIRECTORY=./$(SESSIONS_DIR) $(BUILD_DIR)/$(APPNAME).test -test.coverprofile=$(COVERAGE_DIR)/test-integration-cover.out >/dev/null 2>&1 & echo $$! > $(PID_FILE)
9198
sleep 5
9299
$(VENOM) run tests/features/$(SUITE)
93100
kill `cat $(PID_FILE)` 2> /dev/null || true
@@ -96,19 +103,36 @@ test-integration: $(VENOM) check-default-ports persistence
96103
start-integration: $(VENOM)
97104
$(VENOM) run tests/features/$(SUITE)
98105

99-
coverage/test-cover.out:
106+
# End-to-end UI non-regression tests (Playwright). Builds the client and backend, serves the
107+
# built client through smocker (seeded with tests/sessions), runs the suite, then stops the
108+
# server. Requires the Playwright browser to be installed (npx playwright install chromium).
109+
E2E_MOCK_PORT ?= 8080
110+
E2E_ADMIN_PORT ?= 8081
111+
.PHONY: test-e2e
112+
test-e2e: build persistence
113+
npm run build
114+
SMOCKER_PERSISTENCE_DIRECTORY=./$(SESSIONS_DIR) ./$(BUILD_DIR)/$(APPNAME) \
115+
--static-files ./$(BUILD_DIR)/client \
116+
--mock-server-listen-port=$(E2E_MOCK_PORT) --config-listen-port=$(E2E_ADMIN_PORT) \
117+
> $(BUILD_DIR)/e2e-smocker.log 2>&1 & \
118+
SMK_PID=$$!; \
119+
for i in $$(seq 1 30); do curl -sf localhost:$(E2E_ADMIN_PORT)/version >/dev/null 2>&1 && break; sleep 0.3; done; \
120+
SMOCKER_E2E_URL=http://localhost:$(E2E_ADMIN_PORT) npx playwright test --config tests/e2e/playwright.config.ts; \
121+
RC=$$?; kill $$SMK_PID 2>/dev/null || true; exit $$RC
122+
123+
$(COVERAGE_DIR)/test-cover.out:
100124
$(MAKE) test
101125

102-
coverage/test-integration-cover.out:
126+
$(COVERAGE_DIR)/test-integration-cover.out:
103127
$(MAKE) test-integration
104128

105129
.PHONY: coverage
106-
coverage: $(GOCOVMERGE) coverage/test-cover.out coverage/test-integration-cover.out
107-
$(GOCOVMERGE) coverage/test-cover.out coverage/test-integration-cover.out > coverage/cover.out
130+
coverage: $(GOCOVMERGE) $(COVERAGE_DIR)/test-cover.out $(COVERAGE_DIR)/test-integration-cover.out
131+
$(GOCOVMERGE) $(COVERAGE_DIR)/test-cover.out $(COVERAGE_DIR)/test-integration-cover.out > $(COVERAGE_DIR)/cover.out
108132

109133
.PHONY: clean
110134
clean:
111-
rm -rf ./build ./coverage
135+
rm -rf ./$(BUILD_DIR)
112136

113137
.PHONY: build-docker
114138
build-docker:
@@ -133,9 +157,10 @@ optimize:
133157

134158
build/smocker.tar.gz:
135159
$(MAKE) build
136-
yarn install --frozen-lockfile --ignore-scripts
137-
yarn build
138-
cd build/; tar -czvf smocker.tar.gz *
160+
npm ci --ignore-scripts
161+
npm run build
162+
# Package only the release artifacts, not test/runtime output that may also live in build/.
163+
cd build/; tar -czvf smocker.tar.gz smocker client
139164

140165
.PHONY: release
141166
release: build/smocker.tar.gz

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The documentation is available on [smocker.dev](https://smocker.dev).
2121
- [User Interface](#user-interface)
2222
- [Usage](#usage)
2323
- [Hello, World!](#hello-world)
24+
- [Mock format schema](#mock-format-schema)
2425
- [Development](#development)
2526
- [Backend](#backend)
2627
- [Frontend](#frontend)
@@ -133,6 +134,24 @@ curl -XPOST localhost:8081/reset
133134

134135
For more advanced usage, please read the [project's documentation](https://smocker.dev).
135136

137+
## Mock format schema
138+
139+
A JSON Schema describing the mock format lives at
140+
[`docs/mock.schema.json`](./docs/mock.schema.json). It is generated from and kept in sync with the
141+
Go types (`server/types`): the example mocks under `tests/data` are validated against it in CI, so
142+
it stays accurate. The documentation references this file as the canonical schema.
143+
144+
Editors can use it for autocompletion and validation. With the YAML language server (VS Code,
145+
Neovim, …), add this line at the top of a mocks file:
146+
147+
```yaml
148+
# yaml-language-server: $schema=https://raw.githubusercontent.com/smocker-dev/smocker/main/docs/mock.schema.json
149+
- request:
150+
path: /hello
151+
response:
152+
body: '{"message": "Hello, World!"}'
153+
```
154+
136155
## Development
137156
138157
### Backend

client/components/App.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Base typography for the app: antd's reset leaves <body> without a font-size/family, so pin
2+
// them here (otherwise the browser default 16px applies).
3+
body {
4+
font-size: 14px;
5+
font-family:
6+
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
7+
Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
8+
"Segoe UI Symbol", "Noto Color Emoji";
9+
}
10+
111
html,
212
body,
313
#root,

0 commit comments

Comments
 (0)