Skip to content

Commit aa85cc8

Browse files
chore: Initial WDIO implementation
Initial WDIO implementation with a couple of tests to get us rolling on the migration. Closes: NR-80544
1 parent 6239b2d commit aa85cc8

36 files changed

+14237
-1359
lines changed

.eslintrc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ module.exports = {
1414
'tools/scripts/upload-to-s3.js'
1515
],
1616
parser: '@babel/eslint-parser',
17+
parserOptions: {
18+
requireConfigFile: false,
19+
babelOptions: {
20+
plugins: [
21+
'@babel/plugin-syntax-import-assertions'
22+
]
23+
}
24+
},
1725
env: {
1826
es2022: true
1927
},
@@ -48,7 +56,7 @@ module.exports = {
4856
}
4957
},
5058
{
51-
files: ['src/**/*.test.js'],
59+
files: ['src/**/*.test.js', 'tests/specs/**/*.e2e.js'],
5260
env: {
5361
browser: true,
5462
node: true,

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ npm run unit -- --onlyChanged
66

77
npm run sauce:get-browsers
88
git add tools/jil/util/browsers-supported.json
9+
git add tools/wdio/util/browsers-supported.json
910

1011
for FILE in $STAGED_FILES
1112
do

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,4 @@ To all contributors, we thank you! Without your contribution, this project would
214214
The Browser agent is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
215215

216216
The Browser agent also uses source code from third-party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the [third-party notices document](THIRD_PARTY_NOTICES.md).
217+

newrelic.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ const envConfigs = {
4646
default: {
4747
agent_enabled: false
4848
},
49+
staging: {
50+
agent_enabled: true,
51+
app_name: ['jil-staging'],
52+
license_key: process.env.JIL_NODE_NEW_RELIC_LICENSE_KEY,
53+
host: 'staging-collector.newrelic.com'
54+
},
4955
ci: {
5056
agent_enabled: true,
5157
app_name: ['jil']

package-lock.json

Lines changed: 12381 additions & 1315 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
}
1717
},
1818
"scripts": {
19+
"wdio": "node tools/wdio/bin/cli.js",
1920
"start": "npm-run-all --parallel cdn:watch test-server",
2021
"unit": "jest",
2122
"format": "prettier -w .",
@@ -45,8 +46,8 @@
4546
"cdn:webpack": "npx webpack --progress --config ./webpack.config.js",
4647
"packages:bundle": "webpack -c tools/jil/webpack.modular.js",
4748
"test-server": "node ./tools/jil/bin/server",
48-
"sauce:connect": "node ./tools/jil/bin/sauce",
49-
"sauce:get-browsers": "node ./tools/jil/util/sauce-browsers",
49+
"sauce:connect": "node ./tools/wdio/bin/sauce",
50+
"sauce:get-browsers": "node ./tools/jil/util/sauce-browsers && node ./tools/wdio/util/sauce-browsers",
5051
"tools:test-builds": "npm --prefix ./tools/test-builds/build-time-mfe run build",
5152
"third-party-updates": "oss third-party manifest --includeOptDeps && oss third-party notices --includeOptDeps",
5253
"prepare": "husky install",
@@ -76,6 +77,7 @@
7677
"@babel/eslint-parser": "^7.19.1",
7778
"@babel/plugin-proposal-optional-chaining": "^7.20.7",
7879
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
80+
"@babel/plugin-syntax-import-assertions": "^7.20.0",
7981
"@babel/plugin-transform-modules-commonjs": "^7.18.2",
8082
"@babel/plugin-transform-strict-mode": "^7.18.6",
8183
"@babel/preset-env": "^7.20.2",
@@ -86,6 +88,12 @@
8688
"@newrelic/newrelic-oss-cli": "^0.1.2",
8789
"@newrelic/nr-querypack": "https://git@github.com/newrelic/nr-querypack",
8890
"@octokit/rest": "^19.0.7",
91+
"@wdio/cli": "^8.1.2",
92+
"@wdio/local-runner": "^8.1.2",
93+
"@wdio/mocha-framework": "^8.1.2",
94+
"@wdio/sauce-service": "^8.1.2",
95+
"@wdio/selenium-standalone-service": "^8.1.2",
96+
"@wdio/spec-reporter": "^8.1.2",
8997
"aws-sdk": "^2.894.0",
9098
"babel-jest": "^29.4.1",
9199
"babel-loader": "^8.2.5",
@@ -127,15 +135,17 @@
127135
"mime-types": "^2.1.11",
128136
"minimatch": "^3.0.3",
129137
"multiparty": "^4.1.2",
130-
"newrelic": "^4.11.0",
131-
"node-fetch": "^3.3.1",
138+
"newrelic": "^9.7.5",
139+
"node-fetch": "^3.3.0",
132140
"npm-run-all": "^4.1.5",
133141
"object-inspect": "^1.5.0",
134142
"octokit": "^2.0.14",
135143
"preprocessify": "0.0.6",
136144
"request": "2.74.0",
137145
"sauce-connect-launcher": "^1.2.4",
146+
"saucelabs": "^7.2.0",
138147
"semver": "^5.3.0",
148+
"serialize-anything": "^1.2.3",
139149
"server-destroy": "^1.0.1",
140150
"sinon": "^1.17.5",
141151
"tap-parser": "^1.2.2",

tests/specs/api.e2e.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
const { getTime } = require('../functional/uncat-internal-help.cjs')
2+
const { getErrorsFromResponse } = require('../functional/err/assertion-helpers')
3+
4+
describe('newrelic api', () => {
5+
let testHandle
6+
const init = {
7+
ajax: { deny_list: [], harvestTimeSeconds: 2 },
8+
jserrors: { harvestTimeSeconds: 2 },
9+
metrics: { harvestTimeSeconds: 2 },
10+
page_action: { harvestTimeSeconds: 2 },
11+
page_view_timing: { harvestTimeSeconds: 2 },
12+
session_trace: { harvestTimeSeconds: 2 },
13+
spa: { harvestTimeSeconds: 2 }
14+
}
15+
16+
beforeEach(async () => {
17+
testHandle = await browser.getTestHandle()
18+
})
19+
20+
afterEach(async () => {
21+
await testHandle.destroy()
22+
})
23+
24+
it('should load when sessionStorage is not available', async () => {
25+
const url = await testHandle.assetURL('api/session-storage-disallowed.html', {
26+
loader: 'spa',
27+
init
28+
})
29+
30+
await Promise.all([
31+
testHandle.expectRum(),
32+
browser.url(url)
33+
])
34+
const result = await browser.execute(() => {
35+
return typeof window.newrelic.addToTrace === 'function'
36+
})
37+
38+
expect(result).toEqual(true)
39+
})
40+
41+
describe('setPageViewName api', () => {
42+
it('customTransactionName 1 arg', async () => {
43+
const url = await testHandle.assetURL('api.html', {
44+
loader: 'spa',
45+
init
46+
})
47+
48+
const rumPromise = testHandle.expectRum()
49+
const eventsPromise = testHandle.expectEvents()
50+
const timeSlicePromise = testHandle.expectAjaxTimeSlices()
51+
const resourcesPromise = testHandle.expectResources()
52+
53+
await Promise.all([
54+
browser.url(url),
55+
rumPromise,
56+
eventsPromise,
57+
timeSlicePromise,
58+
resourcesPromise
59+
])
60+
61+
expect((await rumPromise).request.query.ct).toEqual('http://custom.transaction/foo')
62+
expect((await eventsPromise).request.query.ct).toEqual('http://custom.transaction/foo')
63+
expect((await timeSlicePromise).request.query.ct).toEqual('http://custom.transaction/foo')
64+
expect((await resourcesPromise).request.query.ct).toEqual('http://custom.transaction/foo')
65+
})
66+
67+
it('customTransactionName 1 arg unload', async () => {
68+
const url = await testHandle.assetURL('api.html', {
69+
loader: 'spa',
70+
init
71+
})
72+
const unloadUrl = await testHandle.assetURL('/', {
73+
loader: 'spa',
74+
init
75+
})
76+
77+
await browser.url(url)
78+
const metricsPromise = testHandle.expectCustomMetrics()
79+
await browser.url(unloadUrl)
80+
const { request: { body, query } } = await metricsPromise
81+
const time = getTime(body ? JSON.parse(body)?.cm : JSON.parse(query.cm))
82+
83+
expect(query.ct).toEqual('http://custom.transaction/foo')
84+
expect(typeof time).toEqual('number')
85+
expect(time).toBeGreaterThan(0)
86+
})
87+
88+
it('customTransactionName 2 arg', async () => {
89+
const url = await testHandle.assetURL('api2.html', {
90+
loader: 'spa',
91+
init
92+
})
93+
const unloadUrl = await testHandle.assetURL('/', {
94+
loader: 'spa',
95+
init
96+
})
97+
98+
await browser.url(url)
99+
const metricsPromise = testHandle.expectCustomMetrics()
100+
await browser.url(unloadUrl)
101+
const { request: { body, query } } = await metricsPromise
102+
const time = getTime(body ? JSON.parse(body)?.cm : JSON.parse(query.cm))
103+
104+
expect(query.ct).toEqual('http://bar.baz/foo')
105+
expect(typeof time).toEqual('number')
106+
expect(time).toBeGreaterThan(0)
107+
})
108+
})
109+
110+
describe('noticeError api', () => {
111+
it('takes an error object', async () => {
112+
const url = await testHandle.assetURL('api.html', {
113+
loader: 'spa',
114+
init
115+
})
116+
117+
const errorsPromise = testHandle.expectErrors()
118+
await browser.url(url)
119+
const { request } = await errorsPromise
120+
const errorData = getErrorsFromResponse(request)
121+
const params = errorData[0] && errorData[0]['params']
122+
123+
expect(params.exceptionClass).toEqual('Error')
124+
expect(params.message).toEqual('no free taco coupons')
125+
})
126+
127+
it('takes a string', async () => {
128+
const url = await testHandle.assetURL('api/noticeError.html', {
129+
loader: 'spa',
130+
init
131+
})
132+
133+
const errorsPromise = testHandle.expectErrors()
134+
await browser.url(url)
135+
const { request } = await errorsPromise
136+
const errorData = getErrorsFromResponse(request)
137+
const params = errorData[0] && errorData[0]['params']
138+
139+
expect(params.exceptionClass).toEqual('Error')
140+
expect(params.message).toEqual('too many free taco coupons')
141+
})
142+
})
143+
})

tools/jil/bin/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ driver.ready(function () {
1717
console.log('asset server: http://' + config.host + ':' + driver.assetServer.assetServer.port)
1818
console.log('cors server: http://' + config.host + ':' + driver.assetServer.corsServer.port)
1919
console.log('bam server: http://' + config.host + ':' + driver.assetServer.bamServer.port)
20+
console.log('command server: http://' + config.host + ':' + driver.assetServer.commandServer.port)
2021
})

tools/jil/util/browsers-supported.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
},
1010
{
1111
"browserName": "chrome",
12-
"platform": "Windows 11",
13-
"platformName": "Windows 11",
14-
"version": "107",
15-
"browserVersion": "107"
12+
"platform": "Windows 10",
13+
"platformName": "Windows 10",
14+
"version": "108",
15+
"browserVersion": "108"
1616
},
1717
{
1818
"browserName": "chrome",
@@ -23,10 +23,10 @@
2323
},
2424
{
2525
"browserName": "chrome",
26-
"platform": "Windows 11",
27-
"platformName": "Windows 11",
28-
"version": "100",
29-
"browserVersion": "100"
26+
"platform": "Windows 10",
27+
"platformName": "Windows 10",
28+
"version": "101",
29+
"browserVersion": "101"
3030
}
3131
],
3232
"edge": [
@@ -39,10 +39,10 @@
3939
},
4040
{
4141
"browserName": "MicrosoftEdge",
42-
"platform": "Windows 10",
43-
"platformName": "Windows 10",
44-
"version": "107",
45-
"browserVersion": "107"
42+
"platform": "Windows 11",
43+
"platformName": "Windows 11",
44+
"version": "108",
45+
"browserVersion": "108"
4646
},
4747
{
4848
"browserName": "MicrosoftEdge",
@@ -55,8 +55,8 @@
5555
"browserName": "MicrosoftEdge",
5656
"platform": "Windows 10",
5757
"platformName": "Windows 10",
58-
"version": "100",
59-
"browserVersion": "100"
58+
"version": "101",
59+
"browserVersion": "101"
6060
}
6161
],
6262
"safari": [
@@ -82,7 +82,7 @@
8282
{
8383
"browserName": "firefox",
8484
"platform": "Windows 10",
85-
"version": "107"
85+
"version": "108"
8686
},
8787
{
8888
"browserName": "firefox",
@@ -92,7 +92,7 @@
9292
{
9393
"browserName": "firefox",
9494
"platform": "Windows 10",
95-
"version": "100"
95+
"version": "101"
9696
}
9797
],
9898
"android": [

0 commit comments

Comments
 (0)