-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Extract examples from new-style services #1582
Changes from 5 commits
bbe0129
6574cc3
7922038
3c85819
59516f9
3187809
15e1712
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,3 +89,4 @@ typings/ | |
# Temporary build artifacts. | ||
/build | ||
.next | ||
badge-examples.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const { expect } = require('chai'); | ||
|
||
const allBadgeExamples = require('./all-badge-examples'); | ||
|
||
describe('The badge examples', function () { | ||
it('should include AppVeyor, which is added automatically', function () { | ||
const { examples } = allBadgeExamples.getCategory('build'); | ||
|
||
const appVeyorBuildExamples = examples.filter(ex => ex.title.includes('AppVeyor')) | ||
.filter(ex => ! ex.title.includes('tests')); | ||
|
||
expect(appVeyorBuildExamples).to.deep.equal([ | ||
{ | ||
title: 'AppVeyor', | ||
previewUri: '/appveyor/ci/gruntjs/grunt.svg', | ||
exampleUri: undefined, | ||
documentation: undefined, | ||
}, | ||
{ | ||
title: 'AppVeyor branch', | ||
previewUri: '/appveyor/ci/gruntjs/grunt/master.svg', | ||
exampleUri: undefined, | ||
documentation: undefined, | ||
}, | ||
]); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
const allBadgeExamples = require('./all-badge-examples'); | ||
|
||
process.stdout.write(JSON.stringify(allBadgeExamples)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,14 +42,14 @@ module.exports = class AppVeyor extends BaseService { | |
}; | ||
} | ||
|
||
static getExamples() { | ||
static get examples() { | ||
return [ | ||
{ | ||
uri: '/appveyor/ci/gruntjs/grunt', | ||
previewUri: '/appveyor/ci/gruntjs/grunt', | ||
}, | ||
{ | ||
name: 'Branch', | ||
uri: '/appveyor/ci/gruntjs/grunt/master', | ||
title: 'branch', | ||
previewUri: '/appveyor/ci/gruntjs/grunt/master', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a minor duplication, but given we define a base URI pattern in the service class I wonder if there is a way we could define the examples here as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, that makes a lot of sense! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I pushed an update. Could you take a look? It's cool that you brought up |
||
}, | ||
]; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const glob = require('glob'); | ||
|
||
// Match modules with the same name as their containing directory. | ||
// e.g. services/appveyor/appveyor.js | ||
const serviceRegex = /\/services\/(.*)\/\1\.js$/; | ||
|
||
function loadServiceClasses() { | ||
// New-style services | ||
return glob.sync(`${__dirname}/**/*.js`) | ||
.filter(path => serviceRegex.test(path)) | ||
.map(path => require(path)) | ||
} | ||
|
||
function loadTesters() { | ||
return glob.sync(`${__dirname}/**/*.tester.js`) | ||
.map(name => require(name)); | ||
} | ||
|
||
module.exports = { | ||
loadServiceClasses, | ||
loadTesters, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think its worth having another test here which just iterates over all examples (rather than just the appveyor ones) and runs
prepareExample()
on each one. It doesn't have to assert anything other than an error wasn't thrown. That way we'll get a failure on the server tests if an invalid example (without apreviewUri
) is added in a PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's a good idea, though I think this is already happening when this file is
require
d, on account of the call toloadExamples()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one step ahead of me :)