Skip to content

Add assertion to test scripted examples #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/print-example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env jest */
/* eslint-disable no-console */

const assert = require('assert');
const colors = require('@colors/colors/safe');
const fs = require('fs');

Expand Down Expand Up @@ -103,6 +104,24 @@ function runPrintingExample(fn, logName, logTable, logCode, logSeparator, logScr
function printExample(name, makeTable, expected, screenshot) {
let code = makeTable.toString().split('\n').slice(1, -2).join('\n');

/**
* The scripts that generate the cli-table3 docs include "testing" routines
* which never actually get tested. It's unclear whether this was lost or
* dropped somewhere along the way.
*
* Here I've added a simple routine that tests the tables generated with the
* defined expectations.
*
* This proved pertinent when adding a bulk of new documentation examples so
* as to prevent innaccurate documentation and to make some use of the
* "framework" that was already there.
*
* It would be ideal if these "tests" were induced with the jest tests, but
* as is they are only induced within the "print-examples" and "update-docs"
* scripts. —@speedytwenty
*/
assert.equal(makeTable().toString(), expected.join('\n'));

logName(name);
if (screenshot && logScreenShot) {
logScreenShot(screenshot);
Expand Down