Skip to content

Commit

Permalink
update tests and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
electrovir committed Oct 22, 2023
1 parent 2d3df33 commit 965ed87
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 429 deletions.
31 changes: 0 additions & 31 deletions base-configs/base-prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
const fs = require('fs');
const path = require('path');

function toPosixPath(input) {
return input.replace(/\\/g, '/').replace(/^\w+:/, '');
}

const posixDirname = path.posix.dirname(toPosixPath(__dirname));
const packageRoot = path.parse(__dirname).root;

function findClosestPackagePath(dirPath, packageName) {
const currentAttempt = path.join(dirPath, 'node_modules', packageName);

if (fs.existsSync(currentAttempt)) {
return currentAttempt;
} else if (dirPath === packageRoot) {
throw new Error(`Could not find ${packageName} package.`);
} else {
return findClosestPackagePath(path.dirname(dirPath), packageName);
}
}

function getPluginPathFromName(pluginName) {
return path.posix.resolve(
posixDirname,
toPosixPath(findClosestPackagePath(__dirname, pluginName)),
);
}

/**
* @typedef {import('prettier-plugin-multiline-arrays').MultilineArrayOptions} MultilineOptions
*
Expand Down Expand Up @@ -58,6 +29,4 @@ const basePrettierConfig = {

module.exports = {
basePrettierConfig,
/** Export this in case consumers want to add more plugins */
getPluginPathFromName,
};
3 changes: 2 additions & 1 deletion configs/ncu.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export const ncuConfig: RunOptions = {
...baseNcuConfig,
// exclude these
reject: [
...baseNcuConfig.reject,
// ...baseNcuConfig.reject,
'npm-check-updates',
'glob',
],
// include only these
Expand Down
2 changes: 1 addition & 1 deletion configs/src/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<title>Page Name</title>
Expand Down
781 changes: 412 additions & 369 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "virmator",
"version": "9.2.0",
"version": "10.0.0",
"description": "Handle common package configs, commands, and dependencies.",
"keywords": [
"automation",
Expand Down Expand Up @@ -33,7 +33,7 @@
"docs": "npm run compile && ts-node src/scripts/save-help-message.ts && md-code README.md",
"docs:check": "npm run compile && ts-node src/scripts/save-help-message.ts check && md-code --check README.md",
"format": "npm run format:base -- --write --list-different",
"format:base": "prettier \"./**/*.+(ts|json|html|css|md|js)\"",
"format:base": "prettier \"./**/*.+(ts|json|html|css|md|js)\" --config .prettierrc.js",
"publish": "virmator publish \"npm run test:all\"",
"test": "npm run compile && test-as-package mocha --config mocha.config.js",
"test:all": "npm ci && concurrently --color --kill-others-on-fail -c auto --names tests,spelling,format,docs \"npm run compile && npm run test\" \"npm run test:spelling -- --no-progress\" \"npm run test:format\" \"npm run docs:check\"",
Expand Down Expand Up @@ -71,7 +71,7 @@
"@web/test-runner-visual-regression": "^0.8.2",
"chai": "^4.3.10",
"cspell": "^7.3.8",
"dependency-cruiser": "^14.1.2",
"dependency-cruiser": "^15.0.0",
"element-vir": "^16.5.0",
"esbuild": "^0.19.5",
"fs-extra": "^11.1.1",
Expand All @@ -80,14 +80,14 @@
"mocha": "^10.2.0",
"mocha-spec-reporter-with-file-names": "^0.0.3",
"npm-check-updates": "~16.12.3",
"prettier": "^2.8.8",
"prettier-plugin-interpolated-html-tags": "^0.0.4",
"prettier-plugin-jsdoc": "^0.4.2",
"prettier-plugin-multiline-arrays": "^2.0.0",
"prettier": "^3.0.3",
"prettier-plugin-interpolated-html-tags": "^1.0.1",
"prettier-plugin-jsdoc": "^1.1.1",
"prettier-plugin-multiline-arrays": "^3.0.0",
"prettier-plugin-organize-imports": "^3.2.3",
"prettier-plugin-packagejson": "^2.4.6",
"prettier-plugin-sort-json": "^2.0.0",
"prettier-plugin-toml": "^0.3.1",
"prettier-plugin-sort-json": "^3.1.0",
"prettier-plugin-toml": "^1.0.0",
"test-as-package": "^0.0.4",
"test-established-expectations": "^0.5.0",
"ts-node": "^10.9.1",
Expand Down
25 changes: 14 additions & 11 deletions src/augments/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ export function deeplyCombineObjects<
originalObject: OriginalObjectGeneric,
overwriteObject: OverwriteObjectGeneric,
): Overwrite<OriginalObjectGeneric, OverwriteObjectGeneric> {
return getObjectTypedKeys(overwriteObject).reduce((accum, currentKey) => {
const currentNewValue = overwriteObject[currentKey];
const currentOldValue =
typedHasProperty(originalObject, currentKey) && originalObject[currentKey];
if (isObject(currentOldValue) && isObject(currentNewValue)) {
accum[currentKey] = deeplyCombineObjects(currentOldValue, currentNewValue) as any;
} else {
accum[currentKey] = currentNewValue as any;
}
return accum;
}, originalObject as unknown as Overwrite<OriginalObjectGeneric, OverwriteObjectGeneric>);
return getObjectTypedKeys(overwriteObject).reduce(
(accum, currentKey) => {
const currentNewValue = overwriteObject[currentKey];
const currentOldValue =
typedHasProperty(originalObject, currentKey) && originalObject[currentKey];
if (isObject(currentOldValue) && isObject(currentNewValue)) {
accum[currentKey] = deeplyCombineObjects(currentOldValue, currentNewValue) as any;
} else {
accum[currentKey] = currentNewValue as any;
}
return accum;
},
originalObject as unknown as Overwrite<OriginalObjectGeneric, OverwriteObjectGeneric>,
);
}

export function filterToDifferentValues<T extends object>(
Expand Down
15 changes: 9 additions & 6 deletions src/test/run-test-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ export type TestCommandOutput = {
async function runCliCommandForTest<KeyGeneric extends string>(
inputs: RunCliCommandInputs<KeyGeneric>,
): Promise<TestCommandOutput> {
const configFilesExistedBeforeTest = inputs.configFilesToCheck.reduce((accum, configFile) => {
if (existsSync(join(inputs.dir, configFile.copyToPathRelativeToRepoDir))) {
accum[configFile.copyToPathRelativeToRepoDir] = true;
}
return accum;
}, {} as Record<string, boolean>);
const configFilesExistedBeforeTest = inputs.configFilesToCheck.reduce(
(accum, configFile) => {
if (existsSync(join(inputs.dir, configFile.copyToPathRelativeToRepoDir))) {
accum[configFile.copyToPathRelativeToRepoDir] = true;
}
return accum;
},
{} as Record<string, boolean>,
);
await initDirectory(inputs.dir, inputs.keepFiles);
const dirFileNamesBefore = (await readdir(inputs.dir)).sort();
const dirFileContentsBefore = await readAllDirContents({
Expand Down
2 changes: 1 addition & 1 deletion test-files/test-expectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
"dir": "format/invalid-format-repo",
"exitCode": 1,
"key": "fail on format failures in a folder",
"stderr": "[warn] invalid-format.ts [warn] Code style issues found in the above file. Forgot to run Prettier? format failed.",
"stderr": "[warn] invalid-format.ts [warn] Code style issues found in the above file. Run Prettier to fix. format failed.",
"stdout": "Installing prettier... Installing prettier-plugin-jsdoc... Installing prettier-plugin-multiline-arrays... Installing prettier-plugin-organize-imports... Installing prettier-plugin-packagejson... Installing prettier-plugin-sort-json... Installing prettier-plugin-toml... Installing prettier-plugin-interpolated-html-tags... running format... Successfully copied .prettierignore Successfully copied .prettierrc.js node_modules/.bin/prettier --color --cache --cache-strategy content \"./**/*.+(cjs|css|graphql|html|js|json|jsx|less|md|mjs|scss|toml|ts|tsx|yaml|yml)\" --check"
},
"format should update invalid files": {
Expand Down
1 change: 1 addition & 0 deletions test-files/update-configs/full-repo/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.tgz
.DS_Store
.not-committed
/Icon?
coverage/
dist-docs/
Expand Down
1 change: 1 addition & 0 deletions test-files/update-configs/full-repo/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.test.*
*.tgz
.*
.not-committed
/Icon?
/configs/
/coverage/
Expand Down

0 comments on commit 965ed87

Please sign in to comment.