Skip to content

Commit e07ba21

Browse files
authored
chore(js): formatting with prettier (#69)
1 parent d597ab4 commit e07ba21

25 files changed

+923
-899
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ FROM openfeature-provider-js-base AS openfeature-provider-js.test
407407
# Copy confidence-resolver protos (needed by some tests for proto parsing)
408408
COPY confidence-resolver/protos ../../../confidence-resolver/protos
409409
COPY wasm/resolver_state.pb ../../../wasm/resolver_state.pb
410+
COPY openfeature-provider/js/prettier.config.cjs ./
411+
COPY openfeature-provider/js/.prettierignore ./
410412

411413
RUN make test
412414

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules/
2+
dist/
3+
src/proto/
4+
.idea
5+
coverage/*
6+
*.log
7+
api/*
8+
CHANGELOG.md
9+
README.md

openfeature-provider/js/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ install: $(INSTALL_STAMP) $(GEN_TS)
4242
build: $(BUILD_STAMP)
4343

4444
test: $(WASM_ARTIFACT) $(INSTALL_STAMP) $(GEN_TS)
45+
yarn format:check
4546
yarn test --run --exclude='**/*.e2e.test.ts'
4647

4748
test-e2e: $(WASM_ARTIFACT) $(INSTALL_STAMP) $(GEN_TS)

openfeature-provider/js/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,11 @@ The package exports a browser ESM build that compiles the WASM via streaming and
182182
## License
183183

184184
See the root `LICENSE`.
185+
186+
## Formatting
187+
188+
Code is formatted using prettier, you can format all files by running
189+
190+
```sh
191+
yarn format
192+
```

openfeature-provider/js/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"scripts": {
3333
"build": "tsdown",
3434
"dev": "tsdown --watch",
35+
"format": "prettier --config prettier.config.cjs -w .",
36+
"format:check": "prettier --config prettier.config.cjs -c .",
3537
"test": "vitest",
3638
"proto:gen": "rm -rf src/proto && mkdir -p src/proto && protoc --plugin=node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt useOptionals=messages --ts_proto_opt esModuleInterop=true --ts_proto_out src/proto -Iproto api.proto messages.proto test-only.proto"
3739
},
@@ -41,11 +43,13 @@
4143
"devDependencies": {
4244
"@openfeature/core": "^1.9.0",
4345
"@openfeature/server-sdk": "^1.19.0",
46+
"@spotify/prettier-config": "^15.0.0",
4447
"@types/debug": "^4",
4548
"@types/node": "^24.0.1",
4649
"@vitest/coverage-v8": "^3.2.4",
4750
"debug": "^4.4.3",
4851
"dotenv": "^17.2.2",
52+
"prettier": "^2.8.8",
4953
"rolldown": "1.0.0-beta.38",
5054
"ts-proto": "^2.7.3",
5155
"tsdown": "latest",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const baseConfig = require('@spotify/prettier-config');
2+
3+
module.exports = {
4+
...baseConfig,
5+
tabWidth: 2,
6+
useTabs: false,
7+
printWidth: 120,
8+
};

openfeature-provider/js/src/ConfidenceServerProviderLocal.e2e.test.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,30 @@ import { ConfidenceServerProviderLocal } from './ConfidenceServerProviderLocal';
44
import { readFileSync } from 'node:fs';
55
import { WasmResolver } from './WasmResolver';
66

7-
const {
8-
JS_E2E_CONFIDENCE_API_CLIENT_ID,
9-
JS_E2E_CONFIDENCE_API_CLIENT_SECRET,
10-
} = requireEnv('JS_E2E_CONFIDENCE_API_CLIENT_ID', 'JS_E2E_CONFIDENCE_API_CLIENT_SECRET');
7+
const { JS_E2E_CONFIDENCE_API_CLIENT_ID, JS_E2E_CONFIDENCE_API_CLIENT_SECRET } = requireEnv(
8+
'JS_E2E_CONFIDENCE_API_CLIENT_ID',
9+
'JS_E2E_CONFIDENCE_API_CLIENT_SECRET',
10+
);
1111

1212
const moduleBytes = readFileSync(__dirname + '/../../../wasm/confidence_resolver.wasm');
1313
const module = new WebAssembly.Module(moduleBytes);
1414
const resolver = new WasmResolver(module);
1515
const confidenceProvider = new ConfidenceServerProviderLocal(resolver, {
1616
flagClientSecret: 'RxDVTrXvc6op1XxiQ4OaR31dKbJ39aYV',
1717
apiClientId: JS_E2E_CONFIDENCE_API_CLIENT_ID,
18-
apiClientSecret: JS_E2E_CONFIDENCE_API_CLIENT_SECRET
18+
apiClientSecret: JS_E2E_CONFIDENCE_API_CLIENT_SECRET,
1919
});
2020

2121
describe('ConfidenceServerProvider E2E tests', () => {
22-
beforeAll( async () => {
23-
22+
beforeAll(async () => {
2423
await OpenFeature.setProviderAndWait(confidenceProvider);
2524
OpenFeature.setContext({
2625
targetingKey: 'test-a', // control
2726
sticky: false,
2827
});
2928
});
3029

31-
afterAll(() => OpenFeature.close())
30+
afterAll(() => OpenFeature.close());
3231

3332
it('should resolve a boolean e2e', async () => {
3433
const client = OpenFeature.getClient();
@@ -88,24 +87,26 @@ describe('ConfidenceServerProvider E2E tests', () => {
8887

8988
it('should resolve a flag with a sticky resolve', async () => {
9089
const client = OpenFeature.getClient();
91-
const result = await client.getNumberDetails('web-sdk-e2e-flag.double', -1, { targetingKey: 'test-a', sticky: true });
92-
90+
const result = await client.getNumberDetails('web-sdk-e2e-flag.double', -1, {
91+
targetingKey: 'test-a',
92+
sticky: true,
93+
});
94+
9395
// The flag has a running experiment with a sticky assignment. The intake is paused but we should still get the sticky assignment.
9496
// If this test breaks it could mean that the experiment was removed or that the bigtable materialization was cleaned out.
9597
expect(result.value).toBe(99.99);
9698
expect(result.variant).toBe('flags/web-sdk-e2e-flag/variants/sticky');
9799
expect(result.reason).toBe('MATCH');
98-
99100
});
100101
});
101102

102-
function requireEnv<const N extends string[]>(...names:N): Record<N[number],string> {
103+
function requireEnv<const N extends string[]>(...names: N): Record<N[number], string> {
103104
return names.reduce((acc, name) => {
104105
const value = process.env[name];
105-
if(!value) throw new Error(`Missing environment variable ${name}`)
106+
if (!value) throw new Error(`Missing environment variable ${name}`);
106107
return {
107108
...acc,
108-
[name]: value
109+
[name]: value,
109110
};
110-
}, {}) as Record<N[number],string>;
111-
}
111+
}, {}) as Record<N[number], string>;
112+
}

0 commit comments

Comments
 (0)