Skip to content

Commit 93d37b8

Browse files
committed
ci: adding Oxygen contract tests to CI
1 parent 34d45e4 commit 93d37b8

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

.github/workflows/shopify-oxygen.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ jobs:
2626
with:
2727
workspace_name: '@launchdarkly/shopify-oxygen-sdk'
2828
workspace_path: packages/sdk/shopify-oxygen
29+
- name: Install contract test service dependencies
30+
run: yarn workspace @launchdarkly/shopify-oxygen-contract-tests install --no-immutable
31+
- name: Build the test service
32+
run: yarn workspace @launchdarkly/shopify-oxygen-contract-tests build
33+
- name: Launch the test service in the background
34+
run: yarn workspace @launchdarkly/shopify-oxygen-contract-tests start &> /dev/null &
35+
- uses: launchdarkly/gh-actions/actions/contract-tests@61ea6c63de800b495a2fe40c0d4e4ba2a2833ee6
36+
with:
37+
test_service_port: 8000
38+
token: ${{ secrets.GITHUB_TOKEN }}
39+
# Based on run-test-harness.sh from the sdk package
40+
extra_params: '--url http://localhost:8000 --skip "streaming.*" --skip "evaluation.*" --skip "event.*" --skip "service.*" --stop-service-at-end'

packages/sdk/shopify-oxygen/contract-tests/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,16 @@ app.delete('/', (req: Request, res: Response) => {
5050

5151
app.post('/', async (req: Request, res: Response) => {
5252
await clientPool.createClient(req.body, res);
53-
res.send();
5453
});
5554

5655
app.post('/clients/:id', async (req: Request, res: Response) => {
5756
await clientPool.runCommand(req.params.id, req.body, res);
58-
res.send();
5957
});
6058

6159
app.delete('/clients/:id', async (req: Request, res: Response) => {
6260
console.debug('DELETE request received /clients/:id');
6361
console.debug(req.params.id);
6462
await clientPool.deleteClient(req.params.id, res);
65-
res.send();
6663
});
6764

6865
server = app.listen(port, () => {

packages/sdk/shopify-oxygen/contract-tests/src/utils/clientPool.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { init } from '@launchdarkly/shopify-oxygen-sdk';
1010
// general purpose in the future and maybe even come up with some shared ts interface
1111
// to facilitate future contract testing.
1212

13+
// TODO: currently this class will handle the response sending as well, which may technically
14+
// sit outside the scope of what it SHOULD be doing. We should refactor this to be more
15+
// general purpose and allow the caller to handle the response sending.
16+
1317
/**
1418
* ClientPool is a singleton that manages a pool of LDClient instances. Currently there is
1519
* no separation between a managed client and this pool. Which means all of the client specs
@@ -56,9 +60,11 @@ export default class ClientPool {
5660
} catch (err) {
5761
console.error(`Error running command: ${err}`);
5862
res.status(500);
63+
res.send();
5964
}
6065
} else {
6166
res.status(404);
67+
res.send();
6268
}
6369
}
6470

@@ -68,8 +74,10 @@ export default class ClientPool {
6874
client.close();
6975
delete this._clients[id];
7076
res.status(204);
77+
res.send();
7178
} else {
7279
res.status(404);
80+
res.send();
7381
}
7482
}
7583

@@ -83,6 +91,7 @@ export default class ClientPool {
8391
if (!polling) {
8492
// We do not support non-polling clients yet
8593
res.status(400);
94+
res.send();
8695
return;
8796
}
8897
const client = await init(credential, {
@@ -98,12 +107,15 @@ export default class ClientPool {
98107
if (!client.initialized()) {
99108
res.status(500);
100109
client.close();
110+
res.send();
111+
return;
101112
}
102-
this._clients[id] = client;
103113
console.debug(`Creating client with configuration: ${JSON.stringify(options.configuration)}`);
114+
res.send();
104115
} catch (err) {
105116
console.error(`Error creating client: ${err}`);
106117
res.status(500);
118+
res.send();
107119
}
108120
}
109121
}

0 commit comments

Comments
 (0)