seedl-jasmine-saxon

0.1.3 • Public • Published

SeedL Jasmine Saxon

This library helps to test your XSLT, XPATH and Xquery code when using the jasmine testing framework. To use the library you have to install the BaseX database system, first.

Features

The library provides functions to execute XSLT, XPATH and Xquery scripts. You can upload test data before to set up your testing environment. Further, there are library functions to ease the evaluation of the result, which will be checked as part of an assert:

  • noSpaces remove all space characters and new lines from the result string
  • noHeader remove the encoded XML header

Getting started

  • copy basex-example.json to basex.json and enter your personal configuration.

  • install BaseX and start it in the background, e.g. basexserver -S -z on the command line

  • install node.js from http://nodejs.org

  • npm install seedl-jasmine-saxon

  • npm install jasmine-matchers

  • npm install jasmine-given

  • npm install jasmine-node

or include the libraries in your package.json file in the devDependencies section (see source)

Usage

require 'jasmine-matchers'
require 'jasmine-given'

sjs = require('seedl-jasmine-saxon')
processor = sjs.Basex
noSpaces = sjs.noSpaces
noHeader = sjs.noHeader

debug = true

And the tests...

describe 'the basex xslt interface testing script variations', ->

  beforeEach (done) ->
    new processor().setup ->
      done()
    , 'example', '''<?xml version="1.0" encoding="UTF-8"?>
        <data>
          <value>Hello my World!</value>
        </data>'''

  it 'should execute a xslt script', (done) ->
    new processor().xslt done, '''
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
        <xsl:template match="/">
          <xsl:value-of select="data/value/text()" />
        </xsl:template>
      </xsl:stylesheet>
      ''', 'fn:doc("example")', (err, reply) ->
        expect(reply.ok).toBe true
        expect(noHeader(noSpaces(reply.result))).toBe 'HellomyWorld!'

describe 'the basex xslt interface testing data variations', ->

  beforeEach (done) ->
    new processor().setup ->
      done()
    , 'script', '''
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
        <xsl:template match="/">
          <xsl:value-of select="data/value/text()" />
        </xsl:template>
      </xsl:stylesheet>
    '''

  it 'should execute test data', (done) ->
    new processor().xslt done, 'fn:doc("script")', '''<data>
        <value>Hello my World!</value>
      </data>
      ''', (err, reply) ->
        expect(reply.ok).toBe true
        expect(noHeader(noSpaces(reply.result))).toBe 'HellomyWorld!'

describe 'the basex xpath interface', ->

  beforeEach (done) ->
    new processor().setup ->
      done()
    , 'example', '''<?xml version="1.0" encoding="UTF-8"?>
        <data>
          <value>Hello my World!</value>
        </data>
      '''

Here is an example how to output debugging information.

  it 'should execute xpath test with data', (done) ->
    new processor().xpath done, 'fn:doc("example")//value', (err, reply) ->
        expect(reply.ok).toBe true
        expect(noSpaces(reply.result)).toBe '<value>HellomyWorld!</value>'
    , debug

  it 'should execute xpath test without data', (done) ->
    new processor().xpath done, '(1 to 20)[. mod 5 eq 0]', (err, reply) ->
        expect(reply.ok).toBe true
        expect(noSpaces(reply.result)).toBe '5101520'

Package Sidebar

Install

npm i seedl-jasmine-saxon

Weekly Downloads

0

Version

0.1.3

License

BSD-4-Clause

Last publish

Collaborators

  • jgottschick