Skip to content

Commit

Permalink
Merge pull request #607 from escemi-tech/feat/upgrade-jest-28
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime authored May 6, 2022
2 parents 8861cd9 + 2714d44 commit d2e8146
Show file tree
Hide file tree
Showing 5 changed files with 617 additions and 697 deletions.
8 changes: 6 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"import-sort-style-module": "^6.0.0",
"jest": "^27.5.1",
"jest": "^28.0.3",
"lint-staged": "^12.4.1",
"prettier": "^2.6.2",
"prettier-plugin-import-sort": "^0.0.7",
"pretty-quick": "^3.1.3",
"ts-jest": "^27.1.4",
"ts-jest": "^28.0.1",
"typescript": "^4.6.4"
},
"devDependencies": {
Expand Down Expand Up @@ -110,6 +110,10 @@
],
"collectCoverageFrom": [
"**/src/**/*.[jt]s?(x)"
],
"reporters": [
"default",
"github-actions"
]
}
}
24 changes: 6 additions & 18 deletions packages/core/src/tests/project.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, symlinkSync } from "fs";
import { tmpdir } from "os";
import { basename, join, resolve } from "path";
import { join, resolve } from "path";

import { PackageJson } from "../services/PackageJson";
import { PluginService } from "../services/PluginService";
import { safeExec } from "./cli";
import { deleteFolderRecursive } from "./file-system";
import { createTestDir, getTestDirPath, removeTestDir } from "./test-dir";

export const testProjectDir = resolve("__tests__/test-project");

const getTestProjectDirPath = (filename: string) =>
join(tmpdir(), "test-" + basename(filename).split(".")[0]);

const defaultPackageJsonPath = join(testProjectDir, "package.json");
const getTestProjectDirPath = (filename: string) => getTestDirPath("test", filename);

export function createTestProjectDir(filename: string): string {
const testProjectDirPath = getTestProjectDirPath(filename);
if (existsSync(testProjectDirPath)) {
deleteFolderRecursive(testProjectDirPath);
}

mkdirSync(testProjectDirPath);
return testProjectDirPath;
const testDirPath = getTestProjectDirPath(filename);
return createTestDir(testDirPath, true);
}

export function createTestProjectDirWithFixtures(filename: string) {
Expand Down Expand Up @@ -61,10 +52,7 @@ export function restorePackageJson(filename: string): void {

export function removeTestProjectDir(filename: string): void {
const testProjectDirPath = getTestProjectDirPath(filename);
if (!existsSync(testProjectDirPath)) {
throw new Error(`Test project dir "${testProjectDirPath}" does not exist`);
}
deleteFolderRecursive(testProjectDirPath);
removeTestDir(testProjectDirPath);
}

export const createTestMonorepoProjectDir = async (
Expand Down
27 changes: 27 additions & 0 deletions packages/core/src/tests/test-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { existsSync, mkdirSync } from "fs";
import { tmpdir } from "os";
import { basename, join } from "path";

import { deleteFolderRecursive } from "./file-system";

export const getTestDirPath = (dirName: string, filename: string) =>
join(tmpdir(), dirName + "-" + basename(filename).split(".")[0]);

export function createTestDir(testDirPath: string, removeIfExists = false): string {
if (existsSync(testDirPath)) {
if (!removeIfExists) {
return testDirPath;
}
deleteFolderRecursive(testDirPath);
}

mkdirSync(testDirPath);
return testDirPath;
}

export function removeTestDir(testDirPath: string): void {
if (!existsSync(testDirPath)) {
throw new Error(`Test project dir "${testDirPath}" does not exist`);
}
deleteFolderRecursive(testDirPath);
}
4 changes: 4 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
],
"collectCoverageFrom": [
"**/src/**/*.[jt]s?(x)"
],
"reporters": [
"default",
"github-actions"
]
}
}
Loading

0 comments on commit d2e8146

Please sign in to comment.