From 4f5a1ff946fc1693b602fcbbfa1d3ef0be3845f6 Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Tue, 19 Apr 2022 23:42:24 -0400 Subject: [PATCH] factored into TestHelpers.ts file --- .github/workflows/ci.yml | 1 + packages/squiggle-lang/.gitignore | 1 + .../squiggle-lang/__tests__/TS/Jstat_test.ts | 17 ++--------------- .../squiggle-lang/__tests__/TS/Parser_test.ts | 5 +---- .../__tests__/TS/SampleSet_test.ts | 15 +-------------- .../squiggle-lang/__tests__/TS/Scalars_test.ts | 15 ++------------- .../squiggle-lang/__tests__/TS/Symbolic_test.ts | 5 +---- .../squiggle-lang/__tests__/TS/TestHelpers.ts | 17 +++++++++++++++++ packages/squiggle-lang/jest.config.js | 1 + packages/squiggle-lang/package.json | 6 +++--- 10 files changed, 30 insertions(+), 53 deletions(-) create mode 100644 packages/squiggle-lang/__tests__/TS/TestHelpers.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43a23602..bd6e38d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,6 +81,7 @@ jobs: run: yarn coverage:rescript:ci - name: Upload typescript coverage report run: yarn coverage:ts:ci + components-lint: name: Components lint runs-on: ubuntu-latest diff --git a/packages/squiggle-lang/.gitignore b/packages/squiggle-lang/.gitignore index 3653ddf5..4db5c5f4 100644 --- a/packages/squiggle-lang/.gitignore +++ b/packages/squiggle-lang/.gitignore @@ -20,3 +20,4 @@ dist *.coverage _coverage coverage +.nyc_output/ diff --git a/packages/squiggle-lang/__tests__/TS/Jstat_test.ts b/packages/squiggle-lang/__tests__/TS/Jstat_test.ts index d4522ec2..873ae4a8 100644 --- a/packages/squiggle-lang/__tests__/TS/Jstat_test.ts +++ b/packages/squiggle-lang/__tests__/TS/Jstat_test.ts @@ -1,19 +1,6 @@ -import { - run, - Distribution, - squiggleExpression, - errorValueToString, - errorValue, - result, -} from "../../src/js/index"; +import { errorValueToString } from "../../src/js/index"; import * as fc from "fast-check"; - -let testRun = (x: string): any => { - //result => { - return run(x, { sampleCount: 1000, xyPointLength: 100 }); -}; - -let failDefault = () => expect("codepath should never").toBe("be reached"); +import { testRun } from "./TestHelpers"; describe("Jstat: cumulative density function", () => { test("of a normal distribution at 3 stdevs to the right of the mean is within epsilon of 1", () => { diff --git a/packages/squiggle-lang/__tests__/TS/Parser_test.ts b/packages/squiggle-lang/__tests__/TS/Parser_test.ts index d6579c49..124675f2 100644 --- a/packages/squiggle-lang/__tests__/TS/Parser_test.ts +++ b/packages/squiggle-lang/__tests__/TS/Parser_test.ts @@ -4,12 +4,9 @@ import { errorValue, result, } from "../../src/js/index"; +import { testRun } from "./TestHelpers"; import * as fc from "fast-check"; -let testRun = (x: string): result => { - return run(x, { sampleCount: 1000, xyPointLength: 100 }); -}; - describe("Squiggle is whitespace insensitive", () => { test("when assigning a distribution to a name and calling that name", () => { /* diff --git a/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts b/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts index 6733e3c4..2588eb51 100644 --- a/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts +++ b/packages/squiggle-lang/__tests__/TS/SampleSet_test.ts @@ -1,19 +1,6 @@ -import { - run, - Distribution, - squiggleExpression, - errorValueToString, - errorValue, - result, -} from "../../src/js/index"; +import { Distribution } from "../../src/js/index"; import * as fc from "fast-check"; -let testRun = (x: string): result => { - return run(x, { sampleCount: 1000, xyPointLength: 100 }); -}; - -let failDefault = () => expect("codepath should never").toBe("be reached"); - // Beware: float64Array makes it appear in an infinite loop. let arrayGen = () => fc.float32Array({ diff --git a/packages/squiggle-lang/__tests__/TS/Scalars_test.ts b/packages/squiggle-lang/__tests__/TS/Scalars_test.ts index 401ac32a..b91bdb20 100644 --- a/packages/squiggle-lang/__tests__/TS/Scalars_test.ts +++ b/packages/squiggle-lang/__tests__/TS/Scalars_test.ts @@ -1,18 +1,7 @@ -import { - run, - Distribution, - resultMap, - squiggleExpression, - errorValueToString, - errorValue, - result, -} from "../../src/js/index"; +import { errorValueToString } from "../../src/js/index"; +import { testRun } from "./TestHelpers"; import * as fc from "fast-check"; -let testRun = (x: string): result => { - return run(x, { sampleCount: 100, xyPointLength: 100 }); -}; - describe("Scalar manipulation is well-modeled by javascript math", () => { test("in the case of logarithms (with assignment)", () => { fc.assert( diff --git a/packages/squiggle-lang/__tests__/TS/Symbolic_test.ts b/packages/squiggle-lang/__tests__/TS/Symbolic_test.ts index f97adbec..15edbf48 100644 --- a/packages/squiggle-lang/__tests__/TS/Symbolic_test.ts +++ b/packages/squiggle-lang/__tests__/TS/Symbolic_test.ts @@ -5,12 +5,9 @@ import { errorValue, result, } from "../../src/js/index"; +import { testRun } from "./TestHelpers"; import * as fc from "fast-check"; -let testRun = (x: string): result => { - return run(x, { sampleCount: 100, xyPointLength: 100 }); -}; - describe("Symbolic mean", () => { let triangularInputError = { tag: "Error", diff --git a/packages/squiggle-lang/__tests__/TS/TestHelpers.ts b/packages/squiggle-lang/__tests__/TS/TestHelpers.ts new file mode 100644 index 00000000..79dba36b --- /dev/null +++ b/packages/squiggle-lang/__tests__/TS/TestHelpers.ts @@ -0,0 +1,17 @@ +import { + run, + Distribution, + squiggleExpression, + errorValueToString, + errorValue, + result, +} from "../../src/js/index"; + +export function testRun(x: string): any { + //: result => { + return run(x, { sampleCount: 1000, xyPointLength: 100 }); +} + +export function failDefault() { + expect("be reached").toBe("codepath should never be"); +} diff --git a/packages/squiggle-lang/jest.config.js b/packages/squiggle-lang/jest.config.js index 3347de7c..71babb3c 100644 --- a/packages/squiggle-lang/jest.config.js +++ b/packages/squiggle-lang/jest.config.js @@ -9,5 +9,6 @@ module.exports = { ".*Fixtures.bs.js", "/node_modules/", ".*Helpers.bs.js", + ".*Helpers.ts", ], }; diff --git a/packages/squiggle-lang/package.json b/packages/squiggle-lang/package.json index f5f62cf4..3435d595 100644 --- a/packages/squiggle-lang/package.json +++ b/packages/squiggle-lang/package.json @@ -14,9 +14,9 @@ "test:reducer": "jest __tests__/Reducer*/", "test:watch": "jest --watchAll", "coverage:rescript": "rm -f *.coverage; yarn clean; BISECT_ENABLE=yes yarn build; yarn test:rescript; bisect-ppx-report html", - "coverage:ts": "nyc yarn test:ts", - "coverage:rescript:ci": "yarn clean; BISECT_ENABLE=yes yarn build; yarn test; bisect-ppx-report send-to Codecov", - "coverage:ts:ci": "nyc --reporter=lcov yarn test:ts && codecov", + "coverage:ts": "nyc --reporter=lcov yarn test:ts", + "coverage:rescript:ci": "yarn clean; BISECT_ENABLE=yes yarn build; yarn test:rescript; bisect-ppx-report send-to Codecov", + "coverage:ts:ci": "yarn coverage:ts && codecov", "lint:rescript": "./lint.sh", "lint:prettier": "prettier --check .", "lint": "yarn lint:rescript && yarn lint:prettier",