-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from aditya-padhi-kbl/trunk
add ability to run tests and linting in new projects
- Loading branch information
Showing
6 changed files
with
113 additions
and
12 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ mydir | |
myadmin | ||
mystore | ||
myapi | ||
.idea |
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
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,31 @@ | ||
import path from "path"; | ||
import os from "os"; | ||
import fs from "fs"; | ||
import { writeFile, rm, readFile } from "fs/promises"; | ||
import { copy } from "fs-extra"; | ||
import getFilesFromReactionRepo from "./getFilesFromReactionRepo.js"; | ||
import updateJestProcessEnv from "./updateJestProcessEnv.js"; | ||
import getFileFromCore from "./getFileFromCore.js"; | ||
|
||
/** | ||
* This only copies the test utilities from upstream (git) to the target folder | ||
* @param {String} sourcePath git sub-path from which the document will be fetched | ||
* @param {String} destinationPath destination folder | ||
* @returns {Boolean} {Promise<boolean>} return true when successful | ||
*/ | ||
export default async function copyTests(sourcePath, destinationPath) { | ||
const appPrefix = `test_utils${(Math.random() + 1).toString(36).substring(7)}`; | ||
/** | ||
* Create a temporary directory to update the jestProcessEnv received from upstream | ||
*/ | ||
const tempDirectory = fs.mkdtempSync(path.join(os.tmpdir(), appPrefix)); | ||
await getFilesFromReactionRepo(sourcePath, tempDirectory); | ||
const jestProcessEnvConfig = await readFile(path.join(tempDirectory, "util", "jestProcessEnv.json")); | ||
/* write the updated jestProcessEnv in the file available in the temporary directory*/ | ||
await writeFile(path.join(tempDirectory, "util", "jestProcessEnv.json"), JSON.stringify(updateJestProcessEnv(jestProcessEnvConfig), null, 2)); | ||
const jestConfig = await getFileFromCore("jest.config.cjs"); | ||
await Promise.all([copy(tempDirectory, `${destinationPath}/tests`), writeFile(`${destinationPath}/jest.config.cjs`, jestConfig)]); | ||
/* Clean up the temporary directory*/ | ||
await rm(tempDirectory, { recursive: true }); | ||
return true; | ||
} |
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,43 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import os from "os"; | ||
import simpleGit from "simple-git"; | ||
import isCI from "is-ci"; | ||
import { copy } from "fs-extra"; | ||
import rimraf from "rimraf"; | ||
import Logger from "./logger.js"; | ||
import getFileFromCore from "./getFileFromCore.js"; | ||
|
||
/** | ||
* @summary Make local copies of files from remote git repository. It only fetches the contents from reactCommerce.reaction | ||
* @param {String} sourcePath - Where to get the files from the local clone | ||
* @param {String} destinationPath - Where to put the copied files | ||
* @returns {Promise<Boolean>} - true if successful | ||
*/ | ||
const getFilesFromReactionRepo = async (sourcePath, destinationPath) => { | ||
const appPrefix = "reactioncommerce-reaction"; | ||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), appPrefix)); | ||
const gitOptions = { | ||
baseDir: `${tmpDir}`, | ||
binary: "git", | ||
maxConcurrentProcesses: 6 | ||
}; | ||
const git = await simpleGit(gitOptions); | ||
const reactCommerceReactionPackage = await getFileFromCore("package.json"); | ||
const parsedPackage = JSON.parse(reactCommerceReactionPackage); | ||
const { repository: { url: cliRepo } } = parsedPackage; | ||
// On the CI, we need token to access the repo till it's private | ||
const gitRepo = isCI ? `https://${process.env.GH_PUBLISHING_TOKEN}@github.com/reactioncommerce/reaction.git` : cliRepo; | ||
try { | ||
await git.clone(gitRepo, tmpDir, { | ||
"--depth": 1 | ||
}); | ||
} catch (error) { | ||
Logger.error(error); | ||
} | ||
await copy(`${tmpDir}${sourcePath}`, destinationPath); | ||
await rimraf.sync(tmpDir); | ||
return true; | ||
}; | ||
|
||
export default getFilesFromReactionRepo; |
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,6 @@ | ||
const updateJestProcessEnv = (jestProcessEnv) => ({ | ||
...JSON.parse(jestProcessEnv), | ||
MONGO_URL: "mongodb://localhost:27017/test" | ||
}); | ||
|
||
export default updateJestProcessEnv; |