Skip to content

Commit

Permalink
chore: tap@15 (#133)
Browse files Browse the repository at this point in the history
* also move ini.js to lib in preparation for template-oss
* also fix tests to work in windows
  • Loading branch information
wraithgar authored Oct 14, 2021
1 parent 90ca78f commit c2ee801
Show file tree
Hide file tree
Showing 8 changed files with 2,985 additions and 2,722 deletions.
1 change: 1 addition & 0 deletions ini.js → lib/ini.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { hasOwnProperty } = Object.prototype

/* istanbul ignore next */
const eol = typeof process !== 'undefined' &&
process.platform === 'win32' ? '\r\n' : '\n'

Expand Down
5,462 changes: 2,835 additions & 2,627 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"type": "git",
"url": "git://github.com/isaacs/ini.git"
},
"main": "ini.js",
"main": "lib/ini.js",
"scripts": {
"eslint": "eslint",
"lint": "npm run eslint -- ini.js test/*.js",
"lint": "npm run eslint -- lib test",
"lintfix": "npm run lint -- --fix",
"test": "tap",
"snap": "tap",
"posttest": "npm run lint",
"preversion": "npm test",
"postversion": "npm publish",
Expand All @@ -24,7 +25,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"tap": "14"
"tap": "^15.0.10"
},
"license": "ISC",
"files": [
Expand Down
113 changes: 113 additions & 0 deletions tap-snapshots/test/foo.js.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/foo.js TAP decode from file > must match snapshot 1`] = `
Null Object {
" xa n p ": String(
"\\r
yoyoyo\\r\\r
),
"[disturbing]": "hey you never know",
"a": Null Object {
"[]": "a square?",
"av": "a val",
"b": Null Object {
"c": Null Object {
"e": "1",
"j": "2",
},
},
"cr": Array [
"four",
"eight",
],
"e": "{ o: p, a: { av: a val, b: { c: { e: \\"this [value]\\" } } } }",
"j": "\\"{ o: \\"p\\", a: { av: \\"a val\\", b: { c: { e: \\"this [value]\\" } } } }\\"",
},
"a with spaces": "b c",
"ar": Array [
"one",
"three",
"this is included",
],
"br": "warm",
"eq": "eq=eq",
"o": "p",
"s": "something",
"s1": "\\"something'",
"s2": "something else",
"x.y.z": Null Object {
"a.b.c": Null Object {
"a.b.c": "abc",
"nocomment": "this; this is not a comment",
"noHashComment": "this# this is not a comment",
},
"x.y.z": "xyz",
},
"zr": Array [
"deedee",
],
}
`

exports[`test/foo.js TAP encode from data > must match snapshot 1`] = `
o=p
a with spaces=b c
" xa n p "="\\"\\r\\nyoyoyo\\r\\r\\n"
"[disturbing]"=hey you never know
s=something
s1="something'
s2=something else
zr[]=deedee
ar[]=one
ar[]=three
ar[]=this is included
br=warm
eq="eq=eq"
[a]
av=a val
e={ o: p, a: { av: a val, b: { c: { e: "this [value]" } } } }
j="\\"{ o: \\"p\\", a: { av: \\"a val\\", b: { c: { e: \\"this [value]\\" } } } }\\""
"[]"=a square?
cr[]=four
cr[]=eight
[a.b.c]
e=1
j=2
[x\\.y\\.z]
x.y.z=xyz
[x\\.y\\.z.a\\.b\\.c]
a.b.c=abc
nocomment=this\\; this is not a comment
noHashComment=this\\# this is not a comment
`

exports[`test/foo.js TAP encode with option > must match snapshot 1`] = `
[prefix.log]
type=file
[prefix.log.level]
label=debug
value=10
`

exports[`test/foo.js TAP encode with whitespace > must match snapshot 1`] = `
[log]
type = file
[log.level]
label = debug
value = 10
`
6 changes: 3 additions & 3 deletions test/bar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// test that parse(stringify(obj) deepEqu
// test that parse(stringify(obj)

var ini = require('../')
var test = require('tap').test
Expand All @@ -10,11 +10,11 @@ var data = {
'nested boolean': {theDude: {abides: true, rugCount: 1}},
}

test('parse(stringify(x)) deepEqual x', function (t) {
test('parse(stringify(x)) is same as x', function (t) {
for (var k in data) {
var s = ini.stringify(data[k])
t.comment(s, data[k])
t.deepEqual(ini.parse(s), data[k])
t.same(ini.parse(s), data[k])
}

t.end()
Expand Down
114 changes: 27 additions & 87 deletions test/foo.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,46 @@
var i = require('../')
var tap = require('tap')
var test = tap.test
var fs = require('fs')
var path = require('path')
var fixture = path.resolve(__dirname, './fixtures/foo.ini')
var data = fs.readFileSync(fixture, 'utf8')
var expectE = 'o=p\n'
+ 'a with spaces=b c\n'
+ '" xa n p "="\\"\\r\\nyoyoyo\\r\\r\\n"\n'
+ '"[disturbing]"=hey you never know\n'
+ 's=something\n'
+ 's1="something\'\n'
+ 's2=something else\n'
+ 'zr[]=deedee\n'
+ 'ar[]=one\n'
+ 'ar[]=three\n'
+ 'ar[]=this is included\n'
+ 'br=warm\n'
+ 'eq="eq=eq"\n'
+ '\n'
+ '[a]\n'
+ 'av=a val\n'
+ 'e={ o: p, a: '
+ '{ av: a val, b: { c: { e: "this [value]" '
+ '} } } }\nj="\\"{ o: \\"p\\", a: { av:'
+ ' \\"a val\\", b: { c: { e: \\"this [value]'
+ '\\" } } } }\\""\n"[]"=a square?\n'
+ 'cr[]=four\ncr[]=eight\n\n'
+ '[a.b.c]\ne=1\n'
+ 'j=2\n\n[x\\.y\\.z]\nx.y.z=xyz\n\n'
+ '[x\\.y\\.z.a\\.b\\.c]\na.b.c=abc\n'
+ 'nocomment=this\\; this is not a comment\n'
+ 'noHashComment=this\\# this is not a comment\n'
var expectD =
{ o: 'p',
'a with spaces': 'b c',
' xa n p ': '"\r\nyoyoyo\r\r\n',
'[disturbing]': 'hey you never know',
s: 'something',
s1: '"something\'',
s2: 'something else',
zr: ['deedee'],
ar: ['one', 'three', 'this is included'],
br: 'warm',
eq: 'eq=eq',
a:
{ av: 'a val',
e: '{ o: p, a: { av: a val, b: { c: { e: "this [value]" } } } }',
j: '"{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }"',
'[]': 'a square?',
cr: ['four', 'eight'],
b: { c: { e: '1', j: '2' } } },
'x.y.z': {
'x.y.z': 'xyz',
'a.b.c': {
'a.b.c': 'abc',
nocomment: 'this; this is not a comment',
noHashComment: 'this# this is not a comment',
},
},
}
var expectF = '[prefix.log]\n'
+ 'type=file\n\n'
+ '[prefix.log.level]\n'
+ 'label=debug\n'
+ 'value=10\n'
var expectG = '[log]\n'
+ 'type = file\n\n'
+ '[log.level]\n'
+ 'label = debug\n'
+ 'value = 10\n'
const i = require('../')
const tap = require('tap')
const test = tap.test
const fs = require('fs')
const path = require('path')
const fixture = path.resolve(__dirname, './fixtures/foo.ini')
const data = fs.readFileSync(fixture, 'utf8')

tap.cleanSnapshot = s => s.replace(/\r\n/g, '\n')

test('decode from file', function (t) {
var d = i.decode(data)
t.deepEqual(d, expectD)
const d = i.decode(data)
t.matchSnapshot(d)
t.end()
})

test('encode from data', function (t) {
var e = i.encode(expectD)
t.deepEqual(e, expectE)

var obj = {log: { type: 'file', level: {label: 'debug', value: 10} } }
e = i.encode(obj)
t.notEqual(e.slice(0, 1), '\n', 'Never a blank first line')
t.notEqual(e.slice(-2), '\n\n', 'Never a blank final line')
const d = i.decode(data)
const e = i.encode(d)
t.matchSnapshot(e)
t.end()
})

test('never a blank first or last line', function (t) {
const obj = {log: { type: 'file', level: {label: 'debug', value: 10} } }
const e = i.encode(obj)
t.not(e.slice(0, 1), '\n', 'Never a blank first line')
t.not(e.slice(-2), '\n\n', 'Never a blank final line')
t.end()
})

test('encode with option', function (t) {
var obj = {log: { type: 'file', level: {label: 'debug', value: 10} } }
var e = i.encode(obj, {section: 'prefix'})
const obj = {log: { type: 'file', level: {label: 'debug', value: 10} } }
const e = i.encode(obj, {section: 'prefix'})

t.equal(e, expectF)
t.matchSnapshot(e)
t.end()
})

test('encode with whitespace', function (t) {
var obj = {log: { type: 'file', level: {label: 'debug', value: 10} } }
var e = i.encode(obj, {whitespace: true})
const obj = {log: { type: 'file', level: {label: 'debug', value: 10} } }
const e = i.encode(obj, {whitespace: true})

t.equal(e, expectG)
t.matchSnapshot(e)
t.end()
})
2 changes: 1 addition & 1 deletion test/proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ foo = asdfasdf

var res = ini.parse(data)

t.deepEqual(res, Object.assign(Object.create(null), {
t.same(res, Object.assign(Object.create(null), {
'constructor.prototype.foo': 'asdfasdf',
foo: 'baz',
other: Object.assign(Object.create(null), {
Expand Down
2 changes: 1 addition & 1 deletion test/win32.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var t = require('tap')
Object.defineProperty(process, 'platform', { value: 'win32' })
const ini = require('../ini.js')
const ini = require('..')

const res = ini.encode({foo: { bar: 'baz' }})
t.equal(res, '[foo]\r\nbar=baz\r\n')
Expand Down

0 comments on commit c2ee801

Please sign in to comment.