Skip to content

Commit

Permalink
Merge pull request #54 from mark-wiemer/mark-wiemer/52-dependencies
Browse files Browse the repository at this point in the history
Dependency updates, misc cleanup
  • Loading branch information
PanAeon authored Jan 13, 2025
2 parents 0a67882 + 83f0b2a commit b294109
Show file tree
Hide file tree
Showing 7 changed files with 1,456 additions and 1,093 deletions.
993 changes: 645 additions & 348 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
},
"scripts": {
"build": "npx tsc",
"coverage": "npx nyc --reporter=html mocha -r ts-node/register 'test/**/*.test.ts'",
"format": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.ts' --write",
"lint": "tslint -c tslint.json 'src/**/*.ts'",
"test": "mocha -r ts-node/register 'test/**/*.test.ts'"
"coverage": "npx nyc --reporter=html mocha -r ts-node/register \"test/**/*.test.ts\"",
"format": "prettier --config .prettierrc \"src/**/*.ts\" \"test/**/*.ts\" --write",
"lint": "tslint -c tslint.json \"src/**/*.ts\"",
"test": "mocha -r ts-node/register \"test/**/*.test.ts\""
},
"bin": {
"vscode-tmgrammar-test": "./dist/unit.js",
Expand All @@ -40,8 +40,8 @@
"@types/node": "^18.11.9",
"@types/xml2js": "^0.4.11",
"chai": "^4.2.0",
"mocha": "^10.2.0",
"nyc": "^15.0.1",
"mocha": "^11.1.0",
"nyc": "^17.1.0",
"prettier": "^2.1.2",
"ts-node": "^8.10.2",
"tslint": "^5.20.1",
Expand Down
5 changes: 4 additions & 1 deletion src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ export function loadConfiguration(
{},
...grammars.filter((x) => x.language).map((x) => ({ [x.language || '']: x.scopeName }))
)
let extToLang = Object.assign({}, ...ys.map((x: any) => (x.extensions || []).map((e: any) => ({ [e]: x.id }))).flat())
let extToLang = Object.assign(
{},
...ys.map((x: any) => (x.extensions || []).map((e: any) => ({ [e]: x.id }))).flat()
)
extensionToScope = (ext) => scope || langToScope[extToLang[ext]]
}
return { grammars, extensionToScope }
Expand Down
5 changes: 3 additions & 2 deletions src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let { grammars, extensionToScope } = loadConfiguration(options.config, options.s

const limiter = new Bottleneck({
maxConcurrent: 8,
minTime: 0
minTime: 0
})

const registry = createRegistry(grammars)
Expand All @@ -88,7 +88,8 @@ const testResults: Promise<number[]> = Promise.all(
console.log('No scope is associated with the file.')
return TestFailed
}
return limiter.schedule(() => getVSCodeTokens(registry, scope, src))
return limiter
.schedule(() => getVSCodeTokens(registry, scope, src))
.then((tokens) => {
if (fs.existsSync(filename + '.snap')) {
if (options.updateSnapshot) {
Expand Down
40 changes: 23 additions & 17 deletions src/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import glob from 'glob'
import Bottleneck from 'bottleneck'
import { runGrammarTestCase, parseGrammarTestCase, GrammarTestCase, TestFailure } from './unit/index'
import {
Reporter, CompositeReporter,
ConsoleCompactReporter, ConsoleFullReporter,
XunitGenericReporter, XunitGitlabReporter
Reporter,
CompositeReporter,
ConsoleCompactReporter,
ConsoleFullReporter,
XunitGenericReporter,
XunitGitlabReporter
} from './unit/reporter'

import { createRegistry, loadConfiguration, IGrammarConfig } from './common/index'


let packageJson = require('../package.json')

function collectGrammarOpts(value: String, previous: String[]): String[] {
Expand All @@ -31,8 +33,14 @@ program
)
.option('--config <configuration.json>', 'Path to the language configuration, package.json by default')
.option('-c, --compact', 'Display output in the compact format, which is easier to use with VSCode problem matchers')
.option('--xunit-report <report.xml>', 'Path to directory where test reports in the XUnit format will be emitted in addition to console output')
.option('--xunit-format <generic|gitlab>', 'Format of XML reports generated when --xunit-report is used. `gitlab` format is suitable for viewing the results in GitLab CI/CD web GUI')
.option(
'--xunit-report <report.xml>',
'Path to directory where test reports in the XUnit format will be emitted in addition to console output'
)
.option(
'--xunit-format <generic|gitlab>',
'Format of XML reports generated when --xunit-report is used. `gitlab` format is suitable for viewing the results in GitLab CI/CD web GUI'
)
.version(packageJson.version)
.argument(
'<testcases...>',
Expand All @@ -42,7 +50,6 @@ program

const options = program.opts()


const TestFailed = -1
const TestSuccessful = 0

Expand All @@ -57,16 +64,14 @@ if (options.validate) {
}
}


const consoleReporter = options.compact
? new ConsoleCompactReporter()
: new ConsoleFullReporter()
const consoleReporter = options.compact ? new ConsoleCompactReporter() : new ConsoleFullReporter()
const reporter: Reporter = options.xunitReport
? new CompositeReporter(
consoleReporter,
options.xunitFormat === 'gitlab'
? new XunitGitlabReporter(options.xunitReport)
: new XunitGenericReporter(options.xunitReport))
consoleReporter,
options.xunitFormat === 'gitlab'
? new XunitGitlabReporter(options.xunitReport)
: new XunitGenericReporter(options.xunitReport)
)
: consoleReporter

const rawTestCases = program.args.map((x) => glob.sync(x)).flat()
Expand All @@ -78,7 +83,7 @@ if (rawTestCases.length === 0) {

const limiter = new Bottleneck({
maxConcurrent: 8,
minTime: 0
minTime: 0
})

const testResults: Promise<number[]> = Promise.all(
Expand All @@ -93,7 +98,8 @@ const testResults: Promise<number[]> = Promise.all(
})
}
let testCase = tc as GrammarTestCase
return limiter.schedule(() => runGrammarTestCase(registry, testCase))
return limiter
.schedule(() => runGrammarTestCase(registry, testCase))
.then((failures) => {
reporter.reportTestResult(filename, testCase, failures)
return failures.length === 0 ? TestSuccessful : TestFailed
Expand Down
Loading

0 comments on commit b294109

Please sign in to comment.