shawnbot/meta-template

Create integration tests for supported template formats

オープン

#7 opened on 2016/12/01

 (2 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (9 件のフォーク)github user discovery
help wanted

Repository metrics

Stars
 (53 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

The simplest thing here would probably be to have a script that runs a standard set of converted templates (the feature lower common denominator) through a reference implementation of the target engine (ideally a shell one-liner) to ensure that we get the expected output. For instance, we might test the Handlebars conversion with a this, which we might call handlebars:

#!/usr/bin/env node
const fs = require('fs');
const op = require('yargs').argv;
const template = fs.readFileSync(op.template);
const data = JSON.parse(fs.readFileSync(op.data));
console.log(
  require('handlebars').compile(template)(data)
);

which the testing script could call with a diff.sh that looks something like:

#!/bin/bash
# transform the fixture template with the input format
meta-template fixtures/$(1)/template.njk -f $(2) \
  | ./bin/$(2) --data fixtures/$(1)/data.json \
  > fixtures/symbol/$(2).txt
# then diff it against the fixture's expected output
diff fixtures/$(1)/{output,$(2)}.txt

which you'd call with:

./bin/diff.sh symbol handlebars

(or do it in Node.) The layout might look like:

test/
├── fixtures
|   ├── lookup
|   |   ├── data.json
|   |   ├── template.njk
|   |   └── output.txt
|   └── symbol
|       ├── data.json
|       ├── template.njk
|       └── output.txt
├── bin
|   ├── diff.sh
|   ├── handlebars.sh
|   └── liquid.sh
├── handlebars.spec.js
└── liquid.spec.js

@dsingleton, do you have any thoughts on this?

コントリビューターガイド