Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update azure devops pipeline and fix tests #357

Merged
merged 4 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 66 additions & 45 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,68 @@
pool:
vmImage: ubuntu-20.04

parameters:
- name: versionSpec
- name: nodeVersionList
type: object
default: [6, 8, 10, 12, 14, 16]

- name: imageList
type: object
default:
- '6.x'
- '8.x'
- '10.x'
- '12.x'
- '14.x'
- '16.x'

jobs:
- job: build_test_and_publish
displayName: Build, test and publish
steps:
#build on node 8.x
- task: NodeTool@0
inputs:
versionSpec: '8.x'
displayName: Install node

- script: npm install
displayName: npm install

- script: npm run build
displayName: npm run build
#run unit tests on different node versions
- ${{ each version in parameters.versionSpec }}:
- task: NodeTool@0
inputs:
versionSpec: ${{ version }}
displayName: Install node
- script: npm run units
displayName: npm run units
- script: npm run test
displayName: npm run test
#publish if needed
- task: PublishBuildArtifacts@1
condition: and(succeeded(), in(variables['publishBuild'], 'true'))
inputs:
PathtoPublish: "_build"
ArtifactName: "drop"
ArtifactType: "Container"
displayName: Publish build artifacts
default: ['windows-latest', 'ubuntu-latest']

stages:
- stage: Build
displayName: Build typed-rest-client
jobs:
- job: Build_and_Publish
displayName: Build and Publish artifact
pool:
vmImage: 'ubuntu-20.04'
steps:
#build on node 8.x
- task: NodeTool@0
inputs:
versionSpec: '8.x'
displayName: Install node 8

- script: npm install
displayName: npm install

- script: npm run build
displayName: npm run build

- task: PublishPipelineArtifact@1
displayName: Publish _build artifact
inputs:
targetPath: _build
artifactType: pipeline
artifactName: _build

# run unit tests on different platforms and node versions
- stage: Test
displayName: Test typed-rest-client
jobs:
- ${{ each image in parameters.imageList }}:
- ${{ each nodeVersion in parameters.nodeVersionList }}:
- job: Node_os_${{ nodeVersion }}_${{ replace(image,'-','_') }}
displayName: Node.js ${{ nodeVersion }} on ${{ image }}
pool:
vmImage: ${{ image }}
steps:
- task: DownloadPipelineArtifact@2
displayName: Download built typed-rest-client package
inputs:
artifact: _build
path: $(Build.SourcesDirectory)/_build
patterns: '!package-lock.json' #Exclude package-lock.json

- script: npm install
displayName: npm install

- task: NodeTool@0
inputs:
versionSpec: ${{ nodeVersion }}.x
displayName: Install node ${{ nodeVersion }}

- script: npm run units
displayName: npm run units

- script: npm run test
displayName: npm run test
2 changes: 1 addition & 1 deletion make.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ target.test = function() {
console.log("-------Integration Tests-------");
run('tsc -p ./test/tests');
// Increases timeout for each test, which fixes flaky errors in integration tests.
run('mocha test/tests --timeout 60000');
run('mocha test/tests --timeout 180000 --retries 2');
}

//Deprecated since we automatically build in units before testing, keeping for back compat
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 6 additions & 13 deletions test/tests/httptests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import * as path from 'path';

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

const nodeVersionsWithCertificateErrors = [6, 8];
let redirectProtocol = 'https';
if (nodeVersionsWithCertificateErrors.find((nodeVersion) => process.version.startsWith(`v${nodeVersion}.`))) {
console.log('Using protocol HTTP for redirect tests to avoid certificate errors on this node version');
redirectProtocol = 'http';
}

describe('Http Tests', function () {
let _http: httpm.HttpClient;
let _httpbin: httpm.HttpClient;
Expand Down Expand Up @@ -186,30 +179,30 @@ describe('Http Tests', function () {
});

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

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

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

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