diff --git a/package.json b/package.json index 9cdb65d..fea3673 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "lint": "standard", "bench": "node bench/index.js", "preview": "node preview/serve.js", + "snaptests": "TAP_SNAPSHOT=1 npm test", "pretest": "npm run lint", "test": "tap test/*.spec.js --reporter spec --coverage" }, diff --git a/tap-snapshots/test-calc-text-width.spec.js-TAP.test.js b/tap-snapshots/test-calc-text-width.spec.js-TAP.test.js new file mode 100644 index 0000000..ef069d0 --- /dev/null +++ b/tap-snapshots/test-calc-text-width.spec.js-TAP.test.js @@ -0,0 +1,18 @@ +/* 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/calc-text-width.spec.js TAP calc width for "npm" > result is correct 1`] = ` +24.9 +` + +exports[`test/calc-text-width.spec.js TAP calc width for unicode > result is correct 1`] = ` +56 +` + +exports[`test/calc-text-width.spec.js TAP calc width for emojis > result is correct 1`] = ` +33.6 +` diff --git a/test/calc-text-width.spec.js b/test/calc-text-width.spec.js index e78fc57..c25b9e4 100644 --- a/test/calc-text-width.spec.js +++ b/test/calc-text-width.spec.js @@ -9,12 +9,17 @@ tap.test('basic functions', t => { }) tap.test('calc width for "npm"', t => { - t.is(calcWidth('npm'), 24.9, 'result is correct value') + t.matchSnapshot(calcWidth('npm'), 'result is correct') t.end() }) tap.test('calc width for unicode', t => { - t.is(calcWidth('壹佰贰拾叁'), 56, 'result is correct value') + t.matchSnapshot(calcWidth('壹佰贰拾叁'), 'result is correct') + t.end() +}) + +tap.test('calc width for emojis', t => { + t.matchSnapshot(calcWidth('💩🤱🦄', true), 'result is correct') t.end() })