forked from shaka-project/shaka-player
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add tests for new update-issues tool (shaka-project#3900)
This ports over internal tests suggested in shaka-project#3889.
- Loading branch information
1 parent
69b2769
commit d1f00b8
Showing
8 changed files
with
967 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Test Update Issues Tool | ||
|
||
on: | ||
pull_request: # Trigger for pull requests. | ||
types: [opened, synchronize, reopened] | ||
paths: | ||
.github/workflows/tools/update-issues/** | ||
workflow_dispatch: # Allows for manual triggering. | ||
inputs: | ||
ref: | ||
description: "The ref to build and test." | ||
required: False | ||
|
||
jobs: | ||
test: | ||
name: Test Update Issues Tool | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.inputs.ref || github.ref }} | ||
|
||
- name: Test | ||
run: | | ||
cd .github/workflows/tools/update-issues | ||
npm install | ||
npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/*! @license | ||
* Shaka Player | ||
* Copyright 2016 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @fileoverview Mocks for the classes in issues.js | ||
*/ | ||
|
||
function randomInt() { | ||
return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); | ||
} | ||
let nextIssueNumber = 1; | ||
|
||
class MockGitHubObject { | ||
constructor(subclassDefaults, params) { | ||
const defaults = { | ||
id: randomInt(), | ||
ageInDays: 0, | ||
closedDays: 0, | ||
|
||
...subclassDefaults, | ||
}; | ||
|
||
const mergedParams = { | ||
...defaults, | ||
...params, | ||
}; | ||
|
||
for (const k in mergedParams) { | ||
this[k] = mergedParams[k]; | ||
} | ||
} | ||
|
||
toString() { | ||
return JSON.stringify(this, null, ' '); | ||
} | ||
} | ||
|
||
class MockMilestone extends MockGitHubObject { | ||
constructor(params) { | ||
const defaults = { | ||
title: 'MockMilestone', | ||
version: null, | ||
closed: false, | ||
isBacklog: () => false, | ||
}; | ||
|
||
super(defaults, params); | ||
} | ||
} | ||
|
||
class MockComment extends MockGitHubObject { | ||
constructor(params) { | ||
const defaults = { | ||
author: 'SomeUser', | ||
body: 'Howdy!', | ||
authorAssociation: 'NONE', | ||
fromTeam: false, | ||
}; | ||
|
||
super(defaults, params); | ||
} | ||
} | ||
|
||
class MockIssue extends MockGitHubObject { | ||
constructor(params) { | ||
const defaults = { | ||
number: nextIssueNumber++, | ||
author: 'SomeUser', | ||
labels: [], | ||
closed: false, | ||
locked: false, | ||
milestone: null, | ||
comments: [], | ||
}; | ||
|
||
super(defaults, params); | ||
|
||
this.getLabelAgeInDays = | ||
jasmine.createSpy('getLabelAgeInDays') | ||
.and.returnValue(params.labelAgeInDays || 0); | ||
this.addLabel = jasmine.createSpy('addLabel').and.callFake((name) => { | ||
console.log(`Adding label ${name}`); | ||
}); | ||
this.removeLabel = jasmine.createSpy('removeLabel').and.callFake((name) => { | ||
console.log(`Removing label ${name}`); | ||
}); | ||
this.lock = jasmine.createSpy('lock').and.callFake(() => { | ||
console.log('Locking'); | ||
}); | ||
this.unlock = jasmine.createSpy('unlock').and.callFake(() => { | ||
console.log('Unlocking'); | ||
}); | ||
this.close = jasmine.createSpy('close').and.callFake(() => { | ||
console.log('Closing'); | ||
}); | ||
this.reopen = jasmine.createSpy('reopen').and.callFake(() => { | ||
console.log('Reopening'); | ||
}); | ||
this.setMilestone = | ||
jasmine.createSpy('setMilestone').and.callFake((milestone) => { | ||
console.log(`Setting milestone to "${milestone.title}"`); | ||
}); | ||
this.removeMilestone = | ||
jasmine.createSpy('removeMilestone').and.callFake(() => { | ||
console.log('Removing milestone.'); | ||
}); | ||
this.postComment = jasmine.createSpy('postComment').and.callFake((body) => { | ||
console.log(`Posting comment: ${body}`); | ||
}); | ||
this.loadComments = jasmine.createSpy('loadComments'); | ||
} | ||
|
||
hasLabel(name) { | ||
return this.labels.includes(name); | ||
} | ||
|
||
hasAnyLabel(names) { | ||
return this.labels.some(l => names.includes(l)); | ||
} | ||
} | ||
|
||
module.exports = { | ||
MockMilestone, | ||
MockComment, | ||
MockIssue, | ||
}; |
Oops, something went wrong.