Skip to content

Commit a3eb8f1

Browse files
author
Maxim Zaytsev
authored
Update azure devops pipeline and fix tests (#357)
1 parent 9dd700b commit a3eb8f1

File tree

4 files changed

+74
-60
lines changed

4 files changed

+74
-60
lines changed

azure-pipelines.yml

+66-45
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,68 @@
1-
pool:
2-
vmImage: ubuntu-20.04
3-
41
parameters:
5-
- name: versionSpec
2+
- name: nodeVersionList
3+
type: object
4+
default: [6, 8, 10, 12, 14, 16]
5+
6+
- name: imageList
67
type: object
7-
default:
8-
- '6.x'
9-
- '8.x'
10-
- '10.x'
11-
- '12.x'
12-
- '14.x'
13-
- '16.x'
14-
15-
jobs:
16-
- job: build_test_and_publish
17-
displayName: Build, test and publish
18-
steps:
19-
#build on node 8.x
20-
- task: NodeTool@0
21-
inputs:
22-
versionSpec: '8.x'
23-
displayName: Install node
24-
25-
- script: npm install
26-
displayName: npm install
27-
28-
- script: npm run build
29-
displayName: npm run build
30-
#run unit tests on different node versions
31-
- ${{ each version in parameters.versionSpec }}:
32-
- task: NodeTool@0
33-
inputs:
34-
versionSpec: ${{ version }}
35-
displayName: Install node
36-
- script: npm run units
37-
displayName: npm run units
38-
- script: npm run test
39-
displayName: npm run test
40-
#publish if needed
41-
- task: PublishBuildArtifacts@1
42-
condition: and(succeeded(), in(variables['publishBuild'], 'true'))
43-
inputs:
44-
PathtoPublish: "_build"
45-
ArtifactName: "drop"
46-
ArtifactType: "Container"
47-
displayName: Publish build artifacts
8+
default: ['windows-latest', 'ubuntu-latest']
9+
10+
stages:
11+
- stage: Build
12+
displayName: Build typed-rest-client
13+
jobs:
14+
- job: Build_and_Publish
15+
displayName: Build and Publish artifact
16+
pool:
17+
vmImage: 'ubuntu-20.04'
18+
steps:
19+
#build on node 8.x
20+
- task: NodeTool@0
21+
inputs:
22+
versionSpec: '8.x'
23+
displayName: Install node 8
24+
25+
- script: npm install
26+
displayName: npm install
27+
28+
- script: npm run build
29+
displayName: npm run build
30+
31+
- task: PublishPipelineArtifact@1
32+
displayName: Publish _build artifact
33+
inputs:
34+
targetPath: _build
35+
artifactType: pipeline
36+
artifactName: _build
37+
38+
# run unit tests on different platforms and node versions
39+
- stage: Test
40+
displayName: Test typed-rest-client
41+
jobs:
42+
- ${{ each image in parameters.imageList }}:
43+
- ${{ each nodeVersion in parameters.nodeVersionList }}:
44+
- job: Node_os_${{ nodeVersion }}_${{ replace(image,'-','_') }}
45+
displayName: Node.js ${{ nodeVersion }} on ${{ image }}
46+
pool:
47+
vmImage: ${{ image }}
48+
steps:
49+
- task: DownloadPipelineArtifact@2
50+
displayName: Download built typed-rest-client package
51+
inputs:
52+
artifact: _build
53+
path: $(Build.SourcesDirectory)/_build
54+
patterns: '!package-lock.json' #Exclude package-lock.json
55+
56+
- script: npm install
57+
displayName: npm install
58+
59+
- task: NodeTool@0
60+
inputs:
61+
versionSpec: ${{ nodeVersion }}.x
62+
displayName: Install node ${{ nodeVersion }}
63+
64+
- script: npm run units
65+
displayName: npm run units
66+
67+
- script: npm run test
68+
displayName: npm run test

make.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ target.test = function() {
8383
console.log("-------Integration Tests-------");
8484
run('tsc -p ./test/tests');
8585
// Increases timeout for each test, which fixes flaky errors in integration tests.
86-
run('mocha test/tests --timeout 60000');
86+
run('mocha test/tests --timeout 180000 --retries 2');
8787
}
8888

8989
//Deprecated since we automatically build in units before testing, keeping for back compat

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/tests/httptests.ts

+6-13
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ import * as path from 'path';
99

1010
let sampleFilePath: string = path.join(__dirname, 'testoutput.txt');
1111

12-
const nodeVersionsWithCertificateErrors = [6, 8];
13-
let redirectProtocol = 'https';
14-
if (nodeVersionsWithCertificateErrors.find((nodeVersion) => process.version.startsWith(`v${nodeVersion}.`))) {
15-
console.log('Using protocol HTTP for redirect tests to avoid certificate errors on this node version');
16-
redirectProtocol = 'http';
17-
}
18-
1912
describe('Http Tests', function () {
2013
let _http: httpm.HttpClient;
2114
let _httpbin: httpm.HttpClient;
@@ -186,30 +179,30 @@ describe('Http Tests', function () {
186179
});
187180

188181
it('does basic get request with redirects', async() => {
189-
let res: httpm.HttpClientResponse = await _http.get(`${redirectProtocol}://httpbingo.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/get"))
182+
let res: httpm.HttpClientResponse = await _http.get(`https://httpbin.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/anything"))
190183
assert(res.message.statusCode == 200, "status code should be 200");
191184
let body: string = await res.readBody();
192185
let obj:any = JSON.parse(body);
193-
assert(obj.url === "https://httpbin.org/get");
186+
assert(obj.url === "https://httpbin.org/anything");
194187
});
195188

196189
it('does basic get request with redirects (303)', async() => {
197-
let res: httpm.HttpClientResponse = await _http.get(`${redirectProtocol}://httpbingo.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/get") + '&status_code=303')
190+
let res: httpm.HttpClientResponse = await _http.get(`https://httpbin.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/anything") + '&status_code=303')
198191
assert(res.message.statusCode == 200, "status code should be 200");
199192
let body: string = await res.readBody();
200193
let obj:any = JSON.parse(body);
201-
assert(obj.url === "https://httpbin.org/get");
194+
assert(obj.url === "https://httpbin.org/anything");
202195
});
203196

204197
it('returns 404 for not found get request on redirect', async() => {
205-
let res: httpm.HttpClientResponse = await _http.get(`${redirectProtocol}://httpbingo.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/status/404") + '&status_code=303')
198+
let res: httpm.HttpClientResponse = await _http.get(`https://httpbin.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/status/404") + '&status_code=303')
206199
assert(res.message.statusCode == 404, "status code should be 404");
207200
let body: string = await res.readBody();
208201
});
209202

210203
it('does not follow redirects if disabled', async() => {
211204
let http: httpm.HttpClient = new httpm.HttpClient('typed-test-client-tests', null, { allowRedirects: false });
212-
let res: httpm.HttpClientResponse = await http.get(`${redirectProtocol}://httpbingo.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/get"))
205+
let res: httpm.HttpClientResponse = await http.get(`https://httpbin.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/anything"))
213206
assert(res.message.statusCode == 302, "status code should be 302");
214207
let body: string = await res.readBody();
215208
});

0 commit comments

Comments
 (0)