Skip to content
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

Add initial testing framework and example tests #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
The new schematrons are here.
# jats-schematrons

The `schematrons` folder contains Schematron files that implement recommendations developed by the JATS4R group.


## Testing

`npm t` will run the tests in the `__tests__` folder against the XML files in the `testfiles` folder.
16 changes: 16 additions & 0 deletions __tests__/contributors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const validate = require('../lib/validate')

describe('authors and affiliations', () => {
test('aff label', async () => {
const results = await validate('auths-affs-test1.xml')

expect(results.errors).toHaveLength(2)
expect(results.warnings).toHaveLength(1)
})

test('author affiliation xref', async () => {
const results = await validate('auths-affs-test2.xml')

expect(results.errors).toHaveLength(1)
})
})
15 changes: 15 additions & 0 deletions lib/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { readFileSync } = require('fs')
const { parseXmlString } = require('libxmljs')
const { validate } = require('schematron-runner')

module.exports = name => {
const xml = readFileSync(`${__dirname}/../testfiles/${name}`, 'utf8')

const doc = parseXmlString(xml)

if (doc.errors.length) {
throw new Error(doc.errors.map(error => `ERROR: ${error.message}`).join('\n'))
}

return validate(doc.toString(), `${__dirname}/../schematrons/1.0/jats4r.sch`)
}
Loading