Skip to content

Commit 3fe6a24

Browse files
authored
Migrate node CI to github actions to test on different node versions. (#820)
1 parent 2dbdf1a commit 3fe6a24

File tree

12 files changed

+53
-53
lines changed

12 files changed

+53
-53
lines changed

.buildkite/pipeline.yml

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -72,46 +72,6 @@ steps:
7272
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
7373
paths: ['.yarn/cache/']
7474

75-
- label: '[Node] Lint + Test'
76-
key: analytics-node-test
77-
agents:
78-
queue: v1
79-
commands:
80-
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN}
81-
- echo "--- Install dependencies"
82-
- PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn install --immutable
83-
- echo "--- Build bundles"
84-
- yarn run -T node+deps build
85-
- echo "+++ Run tests"
86-
- yarn run -T node lint
87-
- yarn run -T node test
88-
plugins:
89-
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0:
90-
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
91-
paths: ['.yarn/cache/']
92-
93-
- label: '[Node] Integration Tests :perfection:'
94-
key: analytics-node-lint-test
95-
agents:
96-
queue: v1
97-
commands:
98-
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN}
99-
- echo "--- Install dependencies"
100-
- PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn install --immutable
101-
- echo "--- Build bundles"
102-
- yarn turbo run --filter=node-integration-tests build
103-
- echo "+++ Run tests"
104-
- yarn turbo run --filter=node-integration-tests lint
105-
- yarn turbo run --filter=node-integration-tests test
106-
retry:
107-
automatic:
108-
- exit_status: '*'
109-
limit: 2
110-
plugins:
111-
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0:
112-
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
113-
paths: ['.yarn/cache/']
114-
11575
- label: '[Core] Lint + Test'
11676
agents:
11777
queue: v1

.github/workflows/mardown-link-check.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Markdown Links Check
22
on:
3-
push:
3+
schedule:
4+
# Runs once every 3 days
5+
- cron: "0 0 */3 * *"
46
jobs:
57
check-links:
68
name: Check Markdown Links

.github/workflows/node-ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Node CI
2+
on:
3+
push:
4+
env:
5+
HUSKY: 0
6+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
7+
jobs:
8+
test:
9+
name: "Test (Node.js v${{ matrix.node-version }})"
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node-version: [ 14, 16, 18 ]
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: actions/setup-node@v3
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
cache: "yarn"
20+
- run: yarn install --immutable
21+
- run: yarn turbo run --filter='./packages/node*' lint
22+
- run: yarn turbo run --filter='./packages/node*' test
23+
24+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"jest": "^28.1.0",
5454
"lint-staged": "^13.0.0",
5555
"lodash": "^4.17.21",
56-
"nock": "^13.2.9",
56+
"nock": "^13.3.0",
5757
"node-gyp": "^9.0.0",
5858
"prettier": "^2.6.2",
5959
"ts-jest": "^28.0.4",

packages/browser-integration-tests/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"@playwright/test": "^1.28.1",
2222
"@segment/analytics-next": "workspace:^",
2323
"http-server": "14.1.1",
24-
"nock": "^13.2.9",
2524
"tslib": "^2.4.1"
2625
}
2726
}

packages/node-integration-tests/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"@types/autocannon": "^7",
2020
"@types/node": "^16",
2121
"analytics-node": "^6.2.0",
22-
"autocannon": "^7.10.0",
23-
"nock": "^13.2.9"
22+
"autocannon": "^7.10.0"
2423
},
2524
"packageManager": "[email protected]"
2625
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import fetch from 'node-fetch'
2+
3+
const majorVersion = parseInt(
4+
process.version.replace('v', '').split('.')[0],
5+
10
6+
)
7+
8+
if (majorVersion >= 18) {
9+
;(globalThis as any).fetch = fetch // polyfill fetch so nock will work on node >= 18 -- see: https://github.com/nock/nock/issues/2336
10+
}

packages/node-integration-tests/src/server/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import express from 'express'
22
import { Server } from 'http'
33
import { nockRequests } from './nock'
44
import { ServerReport } from './types'
5+
import './fetch-polyfill'
56

67
// always run express in production mode just to be closer to our client's env -- logs less and consumes less memory.
78
process.env.NODE_ENV = 'production'

packages/node/jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
const { createJestTSConfig } = require('@internal/config')
22

3-
module.exports = createJestTSConfig()
3+
module.exports = createJestTSConfig({
4+
setupFilesAfterEnv: ['./jest.setup.js'],
5+
})

packages/node/jest.setup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const fetch = require('node-fetch')
2+
3+
// eslint-disable-next-line no-undef
4+
globalThis.fetch = fetch // polyfill fetch so nock will work correctly on node 18 (https://github.com/nock/nock/issues/2336)

0 commit comments

Comments
 (0)