Skip to content

Commit 22e40fb

Browse files
committed
fix for babel.
1 parent c43bc33 commit 22e40fb

File tree

9 files changed

+855
-56
lines changed

9 files changed

+855
-56
lines changed

babel.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
presets: [
33
['@babel/preset-env', {
44
targets: {
5-
node: 'current'
5+
node: 8
66
}
77
}],
88
'@babel/preset-typescript'

package-lock.json

Lines changed: 799 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
"test": "tests"
99
},
1010
"scripts": {
11-
"watch": "tsc --watch",
12-
"start": "node ./dist/src/index.js",
11+
"type-check": "tsc --noEmit",
12+
"type-check:watch": "npm run type-check -- --watch",
13+
"build": "npm run build:types && npm run build:js",
14+
"build:types": "tsc --emitDeclarationOnly",
15+
"build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --source-maps inline",
1316
"test": "jest --verbose false",
1417
"test:watch": "jest --watch --verbose false"
1518
},
@@ -24,7 +27,10 @@
2427
},
2528
"homepage": "https://github.com/pruner/cli#readme",
2629
"devDependencies": {
30+
"@babel/cli": "^7.12.1",
2731
"@babel/core": "^7.12.3",
32+
"@babel/node": "^7.12.6",
33+
"@babel/plugin-proposal-class-properties": "^7.12.1",
2834
"@babel/preset-env": "^7.12.1",
2935
"@babel/preset-typescript": "^7.12.1",
3036
"@types/chokidar": "^2.1.3",

src/commands/RunCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import parseGitDiff = require('git-diff-parser');
1+
import parseGitDiff from 'git-diff-parser';
22
import {chain, flatMap} from "lodash";
33
import { green, red, white, yellow } from "chalk";
44
import { join } from "path";
55
import { Command } from "./Command";
66
import { useSpinner } from '../console';
77
import git from '../git';
88
import io from '../io';
9-
import chokidar = require('chokidar');
9+
import chokidar from 'chokidar';
1010
import { allProviders, Provider, State, ProviderClass, LineCoverage, Settings } from '../providers';
1111

1212
type Args = {

src/console.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ora = require('ora');
1+
import ora from 'ora';
22

33
export async function useSpinner<T>(text: string, callback: () => Promise<T>) {
44
const spinner = ora(text);

src/dotnet/DotNetProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join } from "path";
22
import { readFile } from "fs/promises";
33
import { Provider, Settings, SettingsQuestions, Test, Tests } from "../providers";
44
import { parseStringPromise } from "xml2js";
5-
import execa = require("execa");
5+
import execa from "execa";
66
import io from "../io";
77
import { Root } from "./altcover";
88
import { chain, range } from "lodash";

src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import execa = require("execa");
1+
import execa from "execa";
22
import io from "./io";
33

44
const declarations = {

tests/dotnet/RunCommand/RunCommand.test.ts

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ let mockCurrentDiff = "";
1717
git.getCurrentDiffText = async () => mockCurrentDiff;
1818

1919
describe("RunCommand", () => {
20+
const currentDirectory = join("tests", "dotnet", "RunCommand");
21+
2022
const cleanup = async () => {
2123
rimraf.sync(join(__dirname, "temp"));
2224
}
@@ -59,26 +61,32 @@ describe("RunCommand", () => {
5961
return result.stdout;
6062
}
6163

62-
const overwriteCode = async (fileName: string) => {
63-
const currentDirectory = join("tests", "dotnet", "RunCommand");
64+
const revertCode = async (fileName: string) => {
65+
const fromPath = join("tests", "dotnet", "sample", "Sample", fileName);
66+
const toPath = join(currentDirectory, "temp", "Sample", fileName);
67+
68+
await replaceCodeFiles(fromPath, toPath);
69+
}
6470

65-
const overwrittenFileName = `${fileName.substr(0, fileName.indexOf("."))}.cs`;
71+
const overwriteCode = async (fileName: string) => {
72+
const fromPath = join(currentDirectory, fileName);
73+
const toPath = join(currentDirectory, "temp", "Sample", `${fileName.substr(0, fileName.indexOf("."))}.cs`);
6674

67-
const relativeSampleFilePath = join("temp", "Sample", overwrittenFileName);
75+
await replaceCodeFiles(fromPath, toPath);
76+
}
6877

69-
const existingFilePath = join(currentDirectory, relativeSampleFilePath);
70-
const templateFilePath = join(currentDirectory, fileName);
78+
const replaceCodeFiles = async (fromPath: string, toPath: string) => {
79+
toPath = join(currentDirectory, toPath);
7180

72-
const overwrittenRelativePath = join(currentDirectory, relativeSampleFilePath);
7381
mockCurrentDiff = await gitDiff(
74-
overwrittenRelativePath,
75-
templateFilePath);
82+
fromPath,
83+
toPath);
7684

77-
const templateFileContents = await io.readFromFile(templateFilePath);
85+
const fromContents = await io.readFromFile(fromPath);
7886

7987
await io.writeToFile(
80-
existingFilePath,
81-
templateFileContents.toString());
88+
toPath,
89+
fromContents.toString());
8290
}
8391

8492
beforeEach(async () => {
@@ -135,4 +143,23 @@ describe("RunCommand", () => {
135143
...lineRange(14, 17)
136144
]);
137145
});
146+
147+
test('run -> change condition -> run -> revert condition -> check coverage', async () => {
148+
await handler({
149+
provider: "dotnet"
150+
});
151+
152+
await overwriteCode("SomeClass.condition-change.cs");
153+
await handler({
154+
provider: "dotnet"
155+
});
156+
157+
await revertCode("SomeClass.cs");
158+
await handler({
159+
provider: "dotnet"
160+
});
161+
162+
const coverage = await getCoveredLineNumbersForFile("SomeClass.cs");
163+
expect(coverage).toEqual(lineRange(10, 17));
164+
});
138165
});

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"compilerOptions": {
33
"outDir": "./dist",
4-
"target": "ES2015",
4+
"target": "ESNext",
55
"lib": ["ESNext"],
66
"module": "CommonJS",
77
"moduleResolution": "node",
8-
"allowSyntheticDefaultImports": false
8+
"allowSyntheticDefaultImports": true,
9+
"declaration": true
910
}
1011
}

0 commit comments

Comments
 (0)