-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stefan Buck
committed
Jul 4, 2018
1 parent
b5afde3
commit 0d0bfb5
Showing
4 changed files
with
80 additions
and
2 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist/ | ||
packages/**/node_modules | ||
e2e/fixtures/ |
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,75 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const util = require('util'); | ||
const recursive = require('recursive-readdir'); | ||
const async = require('async'); | ||
|
||
// This will generate a json file which is consumed by automated.test.js in the following format. | ||
// Checkout out https://github.com/OctoLinker/OctoLinker/blob/master/e2e/README.md for details. | ||
// | ||
// [ | ||
// { | ||
// "url": "https://github.com/OctoLinker/OctoLinker/blob/master/e2e/fixtures/javascript/nodejs/gentle-resonance-3436.js", | ||
// "content": "require('./proud-tooth-7361');", | ||
// "targetUrl": "/javascript/nodejs/proud-tooth-7361.js", | ||
// "lineNumber": 2 | ||
// }, | ||
// ... | ||
// ] | ||
|
||
const repoSlug = process.env.TRAVIS_PULL_REQUEST_SLUG || 'OctoLinker/OctoLinker'; | ||
const branch = process.env.TRAVIS_BRANCH || 'master'; | ||
const fixturesRoot = `https://github.com/${repoSlug}/blob/${branch}/e2e`; | ||
|
||
async function readContent(files) { | ||
const readFile = util.promisify(fs.readFile); | ||
const mapLimit = util.promisify(async.mapLimit); | ||
|
||
return mapLimit(files, 10, async file => { | ||
const content = await readFile(file, 'utf8'); | ||
|
||
return { | ||
file, | ||
content, | ||
}; | ||
}); | ||
} | ||
|
||
function findTests(contents) { | ||
return contents.reduce((memo, { file, content }) => { | ||
const lines = content.split('\n'); | ||
|
||
lines.forEach((line, index) => { | ||
if (line.includes('@OctoLinkerResolve')) { | ||
const lineNumber = index + 2; | ||
const targetUrl = line | ||
.match(/@OctoLinkerResolve\((.*?)\)/)[1] | ||
.replace('<root>', ''); | ||
|
||
const filePath = file.replace(__dirname, ''); | ||
|
||
memo.push({ | ||
url: `${fixturesRoot}${filePath}`, | ||
content: lines[index + 1].trim(), | ||
targetUrl, | ||
lineNumber, | ||
}); | ||
} | ||
}); | ||
|
||
return memo; | ||
}, []); | ||
} | ||
|
||
(async function init() { | ||
const files = await recursive(path.join(__dirname, 'fixtures')); | ||
const contents = await readContent(files); | ||
const out = findTests(contents); | ||
|
||
console.log(out); // eslint-disable-line | ||
|
||
fs.writeFileSync( | ||
path.join(__dirname, 'fixtures.json'), | ||
JSON.stringify(out, null, ' '), | ||
); | ||
})(); |
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