-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added testing with mocha, refactored tests
- Loading branch information
1 parent
b476e25
commit 372e5d6
Showing
12 changed files
with
1,129 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,5 +113,3 @@ out | |
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
test/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"node": true, | ||
"esversion": 8, | ||
"esversion": 9, | ||
"globals": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const {spawn} = require('child_process'); | ||
|
||
const exec = (cmd, args = [], options = {}, stdio = ['inherit', 'inherit', 'inherit']) => new Promise((resolve, reject) => { | ||
console.log(`Started: ${cmd} ${args.join(' ')}`); | ||
const optionsToCLI = { | ||
...options, | ||
stdio | ||
}; | ||
const app = spawn(cmd, args, optionsToCLI); | ||
app.on('close', (code) => { | ||
if (code !== 0) { | ||
const err = new Error(`Invalid status code: ${code}`); | ||
err.code = code; | ||
return reject(err); | ||
} | ||
return resolve(code); | ||
}); | ||
app.on('error', reject); | ||
}); | ||
|
||
module.exports = exec; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const process = require('process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
// language=markdown | ||
const template = `# Readme test | ||
Post list example: | ||
<!-- BLOG-POST-LIST:START --> | ||
<!-- BLOG-POST-LIST:END --> | ||
# Other contents | ||
Test content | ||
`; | ||
fs.writeFile(path.join(__dirname, 'test', 'Readme.md'), template, () => { | ||
console.log("Written test file...."); | ||
process.env.INPUT_MAX_POST_COUNT = "5"; | ||
process.env.INPUT_FEED_LIST = "http://localhost:8080"; | ||
process.env.INPUT_README_PATH = path.join(__dirname, 'test', 'Readme.md'); | ||
process.env.INPUT_DISABLE_SORT = "false"; | ||
process.env.INPUT_TEMPLATE = "default"; | ||
process.env.TEST_MODE = "true"; | ||
const testFile = process.env.DIST ? './dist/blog-post-workflow' :'./blog-post-workflow'; | ||
console.log('Testing: ', testFile); | ||
require(testFile); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,74 @@ | ||
const assert = require('assert'); | ||
const process = require('process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const exec = require('./exec'); | ||
|
||
// language=markdown | ||
const template = `# Readme test | ||
const TEMPLATE = `# Readme test | ||
Post list example: | ||
<!-- BLOG-POST-LIST:START --> | ||
<!-- BLOG-POST-LIST:END --> | ||
# Other contents | ||
Test content | ||
`; | ||
fs.writeFile(path.join(__dirname, 'test', 'Readme.md'), template, () => { | ||
console.log("Written test file...."); | ||
process.env.INPUT_MAX_POST_COUNT = "5"; | ||
process.env.INPUT_FEED_LIST = "http://localhost:8080"; | ||
process.env.INPUT_README_PATH = path.join(__dirname, 'test', 'Readme.md'); | ||
process.env.INPUT_DISABLE_SORT = "false"; | ||
process.env.INPUT_TEMPLATE = "default"; | ||
process.env.TEST_MODE = "true"; | ||
const testFile = process.env.DIST ? './dist/blog-post-workflow' :'./blog-post-workflow'; | ||
console.log('Testing: ', testFile); | ||
require(testFile); | ||
}); | ||
const TEST_FILE = process.env.DIST ? './blog-post-workflow' :'./blog-post-workflow'; | ||
console.log('Testing: ', TEST_FILE); | ||
|
||
// Test block | ||
describe('Blog post workflow tests', function () { | ||
it('Default template readme generated should match the snapshot',async function () { | ||
const README_FILE = 'Readme.md'; | ||
fs.writeFileSync(path.join(__dirname, 'test', README_FILE), TEMPLATE); | ||
const envObj = { | ||
...process.env, | ||
INPUT_MAX_POST_COUNT: "5", | ||
INPUT_FEED_LIST: "http://localhost:8080", | ||
INPUT_README_PATH: path.join(__dirname, 'test', README_FILE), | ||
INPUT_DISABLE_SORT: "false", | ||
INPUT_TEMPLATE: "default", | ||
TEST_MODE: "true" | ||
}; | ||
await exec('node', ['blog-post-workflow.js'],{env: envObj}); | ||
const snapshot = fs.readFileSync(path.join(__dirname, 'test' , README_FILE + '.snap'), "utf-8"); | ||
const newReadme = fs.readFileSync(path.join(__dirname, 'test' , README_FILE), "utf-8"); | ||
assert.equal(snapshot, newReadme); | ||
}); | ||
|
||
it('Sorting disabled readme should be equal to the saved snapshot',async function () { | ||
const README_FILE = 'Readme.sort.md'; | ||
fs.writeFileSync(path.join(__dirname, 'test', README_FILE), TEMPLATE); | ||
const envObj = { | ||
...process.env, | ||
INPUT_MAX_POST_COUNT: "5", | ||
INPUT_FEED_LIST: "http://localhost:8080", | ||
INPUT_README_PATH: path.join(__dirname, 'test', README_FILE), | ||
INPUT_DISABLE_SORT: "true", | ||
INPUT_TEMPLATE: "default", | ||
TEST_MODE: "true" | ||
}; | ||
await exec('node', ['blog-post-workflow.js'],{env: envObj}); | ||
const snapshot = fs.readFileSync(path.join(__dirname, 'test' , README_FILE + '.snap'), "utf-8"); | ||
const newReadme = fs.readFileSync(path.join(__dirname, 'test' , README_FILE), "utf-8"); | ||
assert.equal(snapshot, newReadme); | ||
}); | ||
|
||
it('Custom template readme generated should match the snapshot',async function () { | ||
const README_FILE = 'Readme.custom.md'; | ||
fs.writeFileSync(path.join(__dirname, 'test', README_FILE), TEMPLATE); | ||
const envObj = { | ||
...process.env, | ||
INPUT_MAX_POST_COUNT: "5", | ||
INPUT_FEED_LIST: "http://localhost:8080", | ||
INPUT_README_PATH: path.join(__dirname, 'test', README_FILE), | ||
INPUT_DISABLE_SORT: "false", | ||
INPUT_TEMPLATE: "$newline[$title]($url) $newline", | ||
TEST_MODE: "true", | ||
}; | ||
await exec('node', ['blog-post-workflow.js'],{env: envObj}); | ||
const snapshot = fs.readFileSync(path.join(__dirname, 'test' , README_FILE + '.snap'), "utf-8"); | ||
const newReadme = fs.readFileSync(path.join(__dirname, 'test' , README_FILE), "utf-8"); | ||
assert.equal(snapshot, newReadme); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Readme test | ||
Post list example: | ||
<!-- BLOG-POST-LIST:START --> | ||
[God Mode in browsers: document.designMode = "on"](https://dev.to/gautamkrishnar/god-mode-in-browsers-document-designmode-on-2pmo) | ||
|
||
[Skipping the Chrome "Your connection is not private" warning](https://dev.to/gautamkrishnar/quickbits-1-skipping-the-chrome-your-connection-is-not-private-warning-4kp1) | ||
|
||
[Microsoft Student Partners – Geek is the new rockstar](https://dev.to/gautamkrishnar/microsoft-student-partners--geek-is-the-new-rockstar) | ||
|
||
[An Introduction to NumPy](https://dev.to/gautamkrishnar/an-introduction-to-numpy) | ||
|
||
[Hi, I'm Gautam krishna.R](https://dev.to/gautamkrishnar/hi-im-gautam-krishnar) | ||
<!-- BLOG-POST-LIST:END --> | ||
|
||
# Other contents | ||
Test content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Readme test | ||
Post list example: | ||
<!-- BLOG-POST-LIST:START --> | ||
- [Hi, I'm Gautam krishna.R](https://dev.to/gautamkrishnar/hi-im-gautam-krishnar) | ||
- [God Mode in browsers: document.designMode = "on"](https://dev.to/gautamkrishnar/god-mode-in-browsers-document-designmode-on-2pmo) | ||
- [Microsoft Student Partners – Geek is the new rockstar](https://dev.to/gautamkrishnar/microsoft-student-partners--geek-is-the-new-rockstar) | ||
- [DuckDuckGo – The search engine redefined](https://dev.to/gautamkrishnar/duckduckgo-the-search-engine-redefined-4c7d) | ||
- [Skipping the Chrome "Your connection is not private" warning](https://dev.to/gautamkrishnar/quickbits-1-skipping-the-chrome-your-connection-is-not-private-warning-4kp1) | ||
<!-- BLOG-POST-LIST:END --> | ||
|
||
# Other contents | ||
Test content |
Oops, something went wrong.