Add more tests

This commit is contained in:
Ross Brodbeck 2020-04-16 13:51:24 -04:00
parent 420680dd9b
commit 6e742474aa
3 changed files with 85 additions and 14 deletions

View File

@ -57,9 +57,8 @@ test('processing an issue with no label will make it stale', async () => {
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z') generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z')
]; ];
const processor = new IssueProcessor( const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
DefaultProcessorOptions, p == 1 ? TestIssueList : []
async (p) => p == 1 ? TestIssueList : []
); );
// process our fake issue list // process our fake issue list
@ -74,9 +73,24 @@ test('processing a stale issue will close it', async () => {
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale']) generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale'])
]; ];
const processor = new IssueProcessor( const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
DefaultProcessorOptions, p == 1 ? TestIssueList : []
async (p) => p == 1 ? TestIssueList : [] );
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toEqual(0);
expect(processor.closedIssues.length).toEqual(1);
});
test('processing a stale PR will close it', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale'])
];
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
p == 1 ? TestIssueList : []
); );
// process our fake issue list // process our fake issue list
@ -96,9 +110,8 @@ test('exempt issue labels will not be marked stale', async () => {
let opts = DefaultProcessorOptions; let opts = DefaultProcessorOptions;
opts.exemptIssueLabels = 'Exempt'; opts.exemptIssueLabels = 'Exempt';
const processor = new IssueProcessor( const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
DefaultProcessorOptions, p == 1 ? TestIssueList : []
async (p) => p == 1 ? TestIssueList : []
); );
// process our fake issue list // process our fake issue list
@ -107,3 +120,61 @@ test('exempt issue labels will not be marked stale', async () => {
expect(processor.staleIssues.length).toEqual(0); expect(processor.staleIssues.length).toEqual(0);
expect(processor.closedIssues.length).toEqual(0); expect(processor.closedIssues.length).toEqual(0);
}); });
test('exempt issue labels will not be marked stale (multi issue label with spaces)', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
];
let opts = DefaultProcessorOptions;
opts.exemptIssueLabels = 'Exempt, Cool, None';
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
p == 1 ? TestIssueList : []
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toEqual(0);
expect(processor.closedIssues.length).toEqual(0);
});
test('exempt issue labels will not be marked stale (multi issue label)', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
];
let opts = DefaultProcessorOptions;
opts.exemptIssueLabels = 'Exempt,Cool,None';
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
p == 1 ? TestIssueList : []
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toEqual(0);
expect(processor.closedIssues.length).toEqual(0);
});
test('exempt pr labels will not be marked stale', async () => {
const TestIssueList: Issue[] = [
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool']),
generateIssue(2, 'My first PR', '2020-01-01T17:00:00Z', true, ['Cool']),
generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false)
];
let opts = DefaultProcessorOptions;
opts.exemptIssueLabels = 'Cool';
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
p == 1 ? TestIssueList : []
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toEqual(2); // PR should get processed even though it has an exempt **issue** label
});

8
dist/index.js vendored
View File

@ -8457,12 +8457,12 @@ class IssueProcessor {
if (getIssues) { if (getIssues) {
this.getIssues = getIssues; this.getIssues = getIssues;
} }
if (this.options.debugOnly) {
core.warning('Executing in debug mode. Debug output will be written but no issues will be processed.');
}
} }
processIssues(page = 1) { processIssues(page = 1) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (this.options.debugOnly) {
core.warning('Executing in debug mode. Debug output will be written but no issues will be processed.');
}
if (this.operationsLeft <= 0) { if (this.operationsLeft <= 0) {
core.warning('Reached max number of operations to process. Exiting.'); core.warning('Reached max number of operations to process. Exiting.');
return 0; return 0;
@ -8582,7 +8582,7 @@ class IssueProcessor {
// In this case, we'd prefer to just return an empty array indicating no labels // In this case, we'd prefer to just return an empty array indicating no labels
if (!s.length) if (!s.length)
return []; return [];
return s.split(','); return s.split(',').map(l => l.trim());
} }
} }
exports.IssueProcessor = IssueProcessor; exports.IssueProcessor = IssueProcessor;

View File

@ -225,6 +225,6 @@ export class IssueProcessor {
// String.prototype.split defaults to [''] when called on an empty string // String.prototype.split defaults to [''] when called on an empty string
// In this case, we'd prefer to just return an empty array indicating no labels // In this case, we'd prefer to just return an empty array indicating no labels
if (!s.length) return []; if (!s.length) return [];
return s.split(','); return s.split(',').map(l => l.trim());
} }
} }