diff --git a/components/git/wpt.js b/components/git/wpt.js index ed8ba7de..969dbfc8 100644 --- a/components/git/wpt.js +++ b/components/git/wpt.js @@ -1,20 +1,18 @@ 'use strict'; -const yargs = require('yargs'); +const fs = require('fs'); +const path = require('path'); const Request = require('../../lib/request'); const CLI = require('../../lib/cli'); const auth = require('../../lib/auth'); const { WPTUpdater, HarnessUpdater } = require('../../lib/wpt'); const { runPromise } = require('../../lib/run'); -// TODO: read this from test/wpt/status/*.json -const SUPPORTED_TESTS = ['url', 'console', 'encoding']; function builder(yargs) { return yargs .positional('name', { - describe: 'Subset of the WPT to update, e.g. \'url\'', - type: 'string', - choices: ['all', 'harness'].concat(SUPPORTED_TESTS) + describe: 'Subset of the WPT to update, e.g. \'harness\', \'url\'', + type: 'string' }) .options({ nodedir: { @@ -34,18 +32,28 @@ async function main(argv) { const request = new Request(credentials); const updaters = []; + + const statusFolder = path.join(nodedir, 'test', 'wpt', 'status'); + let supported = []; + if (fs.existsSync(statusFolder)) { + const jsons = fs.readdirSync(statusFolder); + supported = jsons.map(item => item.replace('.json', '')); + } else { + cli.warn(`Please create the status JSON files in ${statusFolder}`); + } + if (name === 'all') { updaters.push(new HarnessUpdater(cli, request, nodedir)); - for (const item of SUPPORTED_TESTS) { + for (const item of supported) { updaters.push(new WPTUpdater(item, cli, request, nodedir)); } - } else if (SUPPORTED_TESTS.includes(name)) { - updaters.push(new WPTUpdater(name, cli, request, nodedir)); } else if (name === 'harness') { updaters.push(new HarnessUpdater(cli, request, nodedir)); } else { - yargs.showHelp(); - return; + if (!supported.includes(name)) { + cli.warn(`Please create ${name}.json in ${statusFolder}`); + } + updaters.push(new WPTUpdater(name, cli, request, nodedir)); } for (const updater of updaters) { diff --git a/lib/wpt/harness.js b/lib/wpt/harness.js deleted file mode 100644 index 550777d9..00000000 --- a/lib/wpt/harness.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -const { - WPTUpdater -} = require('./'); - -class HarnessUpdater extends WPTUpdater { - constructor(cli, request, nodedir) { - super('resources', cli, request, nodedir); - } - - async update() { - const harnessPath = this.fixtures(this.path, 'testharness.js'); - this.cli.startSpinner(`Downloading ${harnessPath}...`); - await this.pullTextFile(this.fixtures(this.path), 'testharness.js'); - this.cli.stopSpinner(`Downloaded ${harnessPath}`); - const lastCommit = this.tree.lastCommit; - await this.updateVersions({ - harness: { commit: lastCommit, path: 'resources' } - }); - } -} - -module.exports = HarnessUpdater;