Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Commit

Permalink
added the readme and the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shrikster committed Mar 22, 2019
1 parent a93de33 commit a630e7f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ requests:
method: GET
```
## Use strest file name as paramter in the tests
You can use the strest file name as a parmater in the tests .
## Use strest file name as parameter in the tests
You can use the strest file name as a parameter in the tests .
*note* that the strest suffix is removed
Expand All @@ -350,6 +350,35 @@ requests:
expect: 200
```
## Using dates and dates format
You can insert dates times plus format them using the custom [nunjucks date filter](https://www.npmjs.com/package/nunjucks-date)
under the hood its a wrapper for [momentjs](https://momentjs.com/) so all its [formatting](https://momentjs.com/docs/#/displaying/) is supported
**Usage**
You can use the date filter inside a nunjuck brackets in the request and inside the validate parts.
```yml
requests:
moment-in-request:
request:
url: https://postman-echo.com/get
method: GET
queryString:
- name: foo
value: <$ now | date('YYYY') $>
validate:
- jsonpath: content.args.foo
expect: "<$ '2019-10-10' | date('YYYY') $>"
moment-in-validate:
request:
url: https://postman-echo.com/time/format?timestamp=2019-10-10&format=YYYY
method: GET
validate:
- jsonpath: content.format
expect: "<$ '2019-10-10' | date('YYYY') $>"
```
## Response Validation
The immediate response is stored in [HAR Format](http://www.softwareishard.com/blog/har-12-spec/#response)
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"line-number": "0.1.0",
"mkdirp": "^0.5.1",
"nunjucks": "^3.1.3",
"nunjucks-date": "^1.2.0",
"ora": "^3.0.0",
"recursive-readdir": "^2.2.2",
"request-to-curl": "^0.1.1",
Expand Down Expand Up @@ -60,6 +61,7 @@
"@types/jsonpath": "^0.2.0",
"@types/node": "^10.9.4",
"@types/nunjucks": "^3.1.0",
"@types/nunjucks-date": "0.0.6",
"@types/ora": "^1.3.4",
"@types/recursive-readdir": "^2.2.0",
"jest": "^23.6.0",
Expand Down
5 changes: 5 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import * as yaml from 'js-yaml';
import * as jsonfile from 'jsonfile'
import * as path from 'path';
import * as Ajv from 'ajv';
import * as nunjucksDate from 'nunjucks-date';

var deepEql = require("deep-eql");
var lineNumber = require('line-number');
var getLineFromPos = require('get-line-from-pos');

require('request-to-curl');

nunjucksDate.setDefaultFormat('MMMM Do YYYY, h:mm:ss a');
const nunjucksEnv = nunjucks.configure(".", {
tags: {
blockStart: '<%',
Expand All @@ -29,6 +32,8 @@ const nunjucksEnv = nunjucks.configure(".", {
},
throwOnUndefined: true
});

nunjucksDate.install(nunjucksEnv);
nunjucksEnv.addGlobal('Faker', function (faked: string) {
return faker.fake(`{{${faked}}}`);
})
Expand Down
20 changes: 20 additions & 0 deletions tests/success/Value/moment.strest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2

requests:
moment-in-request:
request:
url: https://postman-echo.com/get
method: GET
queryString:
- name: foo
value: <$ now | date('YYYY') $>
validate:
- jsonpath: content.args.foo
expect: "<$ '2019-10-10' | date('YYYY') $>"
moment-in-validate:
request:
url: https://postman-echo.com/time/format?timestamp=2019-10-10&format=YYYY
method: GET
validate:
- jsonpath: content.format
expect: "<$ '2019-10-10' | date('YYYY') $>"

0 comments on commit a630e7f

Please sign in to comment.