Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamkrishnar committed Jan 8, 2024
1 parent 7d14032 commit ca8c826
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 21 deletions.
14 changes: 14 additions & 0 deletions test/categories-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const {DEFAULT_TEST_ENV} = require('./testUtils/default-env');
const {runAndCompareSnap} = require('./testUtils/testUtils');
describe('Generated readme with categories template', function () {
it('should match the snapshot', async function () {
const envObj = {
...process.env,
...DEFAULT_TEST_ENV,
INPUT_FEED_LIST: 'http://localhost:8080',
INPUT_TEMPLATE: '$categories',
INPUT_CATEGORIES_TEMPLATE: '$category<br/>'
};
await runAndCompareSnap('Readme.categories.template.md', envObj);
});
});
13 changes: 13 additions & 0 deletions test/categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {DEFAULT_TEST_ENV} = require('./testUtils/default-env');
const {runAndCompareSnap} = require('./testUtils/testUtils');
describe('Generated readme with categories names', function () {
it('should match the snapshot', async function () {
const envObj = {
...process.env,
...DEFAULT_TEST_ENV,
INPUT_FEED_LIST: 'http://localhost:8080',
INPUT_TEMPLATE: '$categories',
};
await runAndCompareSnap('Readme.categories.md', envObj);
});
});
13 changes: 13 additions & 0 deletions test/duplicate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {DEFAULT_TEST_ENV} = require('./testUtils/default-env');
const {runAndCompareSnap} = require('./testUtils/testUtils');
describe('Generated readme with remove duplicates flag', function () {
it('should match the snapshot', async function () {
const envObj = {
...process.env,
...DEFAULT_TEST_ENV,
INPUT_FEED_LIST: 'http://localhost:8080/duplicates',
INPUT_REMOVE_DUPLICATES: 'true'
};
await runAndCompareSnap('Readme.removeDuplicates.md', envObj);
});
});
15 changes: 15 additions & 0 deletions test/feed-names.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {DEFAULT_TEST_ENV} = require('./testUtils/default-env');
const {runAndCompareSnap} = require('./testUtils/testUtils');
describe('Generated readme with feed names', function () {
it('should match the snapshot', async function () {
const envObj = {
...process.env,
...DEFAULT_TEST_ENV,
INPUT_FEED_LIST: 'http://localhost:8080,http://localhost:8080,http://localhost:8080',
INPUT_FEED_NAMES: 'hello,,world',
INPUT_TEMPLATE: '$newline - $feedName -> $title ',
INPUT_MAX_POST_COUNT: '100',
};
await runAndCompareSnap('Readme.feedNames.md', envObj);
});
});
12 changes: 12 additions & 0 deletions test/js-manipulation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {DEFAULT_TEST_ENV} = require('./testUtils/default-env');
const {runAndCompareSnap} = require('./testUtils/testUtils');
describe('Generated readme with advanced manipulation via JS', function () {
it('should match the snapshot', async function () {
const envObj = {
...process.env,
...DEFAULT_TEST_ENV,
INPUT_ITEM_EXEC: 'post.title=post.title.replace("Gautam",""); post.title=post.title.replace("browser","");'
};
await runAndCompareSnap('Readme.exec.md', envObj);
});
});
13 changes: 13 additions & 0 deletions test/retry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {DEFAULT_TEST_ENV} = require('./testUtils/default-env');
const {runAndCompareSnap} = require('./testUtils/testUtils');
describe('Readme generated after retry', function () {
it('should match the snapshot', async function () {
const envObj = {
...process.env,
...DEFAULT_TEST_ENV,
INPUT_FEED_LIST: 'http://localhost:8080/failtest',
INPUT_RETRY_COUNT: '5'
};
await runAndCompareSnap('Readme.retry.md', envObj);
}).timeout(20 * 1000);
});
7 changes: 0 additions & 7 deletions test/snapshots/Readme.filter_dates.currentMonth.md.snap

This file was deleted.

7 changes: 0 additions & 7 deletions test/snapshots/Readme.filter_dates.currentYear.md.snap

This file was deleted.

7 changes: 0 additions & 7 deletions test/snapshots/Readme.filter_dates.daysAgo.md.snap

This file was deleted.

13 changes: 13 additions & 0 deletions test/truncated description.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {DEFAULT_TEST_ENV} = require('./testUtils/default-env');
const {runAndCompareSnap} = require('./testUtils/testUtils');
describe('Generated readme with truncated description', function () {
it('should match the snapshot', async function () {
const envObj = {
...process.env,
...DEFAULT_TEST_ENV,
INPUT_DESCRIPTION_MAX_LENGTH: '10',
INPUT_TEMPLATE: '$description $newline'
};
await runAndCompareSnap('Readme.truncate.description.md', envObj);
});
});
7 changes: 7 additions & 0 deletions test/unit-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const assert = require('assert');
const {escapeHTML} = require("../src/utils");
describe('Unit Tests', function () {
it('escapeHTML should work as expected', function () {
assert.strictEqual(escapeHTML('<hello>()\'"'), '&lt;hello&gt;&lpar;&rpar;&#39;&quot;');
});
});
13 changes: 13 additions & 0 deletions test/validation-flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {DEFAULT_TEST_ENV} = require('./testUtils/default-env');
const {runAndCompareSnap} = require('./testUtils/testUtils');
describe('Generated readme with no validation flag', function () {
it('should match the snapshot', async function () {
const envObj = {
...process.env,
...DEFAULT_TEST_ENV,
INPUT_FEED_LIST: 'http://localhost:8080/empty-tags',
INPUT_DISABLE_ITEM_VALIDATION: 'true'
};
await runAndCompareSnap('Readme.emptyTags.md', envObj);
});
});

0 comments on commit ca8c826

Please sign in to comment.