From aaa8390073e2f523d8e40c3ed259736bba3a7ab3 Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Fri, 29 Nov 2024 11:10:12 +0100 Subject: [PATCH] revert: unwanted state modification --- codecov.yml | 2 +- package.json | 12 +----------- packages/core-tests/package.json | 10 ++++++++++ packages/core-tests/test-setup.js | 17 +++++++++++++++++ packages/core/models/shapes/reducers.ts | 3 ++- test-setup.js | 11 ----------- 6 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 packages/core-tests/test-setup.js delete mode 100644 test-setup.js diff --git a/codecov.yml b/codecov.yml index 03950b64..231f893c 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,6 +1,6 @@ ignore: - demos - - test-setup.js + - packages/core-tests/test-setup.js - karma.conf.js - types - packages/*/test diff --git a/package.json b/package.json index 506e71ad..2cef84cb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lint": "eslint . --ext .ts --quiet --ignore-path .gitignore --ignore-path .eslintignore", "build": "wsrun -m build", "test": "run-p test:*", - "test:core": "c8 --all -o coverage/core --reporter=lcov mocha --recursive 'packages/core-tests/**/*.test.ts'", + "test:core": "c8 --all -o coverage/core --reporter=lcov npm run -w @hydrofoil/shaperone-core-tests test", "test:web": "web-test-runner", "release": "changeset publish", "docs": "docsify serve ./dist", @@ -28,7 +28,6 @@ "@web/dev-server-rollup": "^0.6.4", "@web/test-runner": "^0.19", "c8": "^7.1.2", - "chai-snapshot-matcher": "^1.0.6", "docsify-cli": "^4.4.1", "es-dev-commonjs-transformer": "^0.2.0", "eslint-import-resolver-typescript": "^3.6.1", @@ -52,15 +51,6 @@ "resolutions": { "@polymer/polymer": "3.4.1" }, - "mocha": { - "watch-files": [ - "./**/*.ts" - ], - "require": [ - "test-setup.js" - ], - "loader": "ts-node/esm/transpile-only" - }, "lint-staged": { "*.{js,ts}": [ "eslint --fix --quiet" diff --git a/packages/core-tests/package.json b/packages/core-tests/package.json index aef2a423..d6de220c 100644 --- a/packages/core-tests/package.json +++ b/packages/core-tests/package.json @@ -3,6 +3,9 @@ "private": true, "version": "0.1.1", "type": "module", + "scripts": { + "test": "mocha \"**/*.ts\"" + }, "devDependencies": { "@hydrofoil/shaperone-core": "*", "@rdfine/shacl": "^0.10.5", @@ -17,10 +20,17 @@ "@types/mocha": "^9.1.1", "@types/sinon-chai": "^3.2.4", "autoesm": "^1.0.5", + "chai-snapshot-matcher": "^1.0.6", "chai-subset": "^1.6.0", "chai-quantifiers": "^1.0.10", "deepmerge": "^4.2.2", "promise-the-world": "^1.0.1", "rdf-dataset-ext": "^1.1.0" + }, + "mocha": { + "require": [ + "./test-setup.js" + ], + "loader": "ts-node/esm/transpile-only" } } diff --git a/packages/core-tests/test-setup.js b/packages/core-tests/test-setup.js new file mode 100644 index 00000000..f472593a --- /dev/null +++ b/packages/core-tests/test-setup.js @@ -0,0 +1,17 @@ +import 'chai-snapshot-matcher' +import chaiQuantifiers from 'chai-quantifiers' +import chai from 'chai' +import sinonChai from 'sinon-chai' +import chaiSubset from 'chai-subset' +import { setEnv } from '@hydrofoil/shaperone-core/env.js' +import rdf from '@zazuko/env' + +chai.use(sinonChai) +chai.use(chaiQuantifiers) +chai.use(chaiSubset) + +export const mochaHooks = { + beforeAll() { + setEnv(rdf) + }, +} diff --git a/packages/core/models/shapes/reducers.ts b/packages/core/models/shapes/reducers.ts index 0775c269..987855bd 100644 --- a/packages/core/models/shapes/reducers.ts +++ b/packages/core/models/shapes/reducers.ts @@ -44,16 +44,17 @@ export const setGraph = formStateReducer((state: ShapeState, { shapesGraph }: Se const newAnyPointer = shapesGraph !== state.shapesGraph && (!shapesGraph.term || !state.shapesGraph?.term) const shapes = findShapes(shapesGraph) - draft.shapes = shapes if (newDataset || newAnyPointer) { // pointer to a different dataset draft.shapesGraph = shapesGraph + draft.shapes = shapes draft.preferredRootShape = getPreferredShape(shapesGraph, shapes) return } if (shapesGraph.term && !shapesGraph.term.equals(state.shapesGraph?.term)) { // same dataset, changed pointer + draft.shapes = shapes draft.preferredRootShape = getPreferredShape(shapesGraph, shapes) } }), emptyState) diff --git a/test-setup.js b/test-setup.js deleted file mode 100644 index 8ba643f4..00000000 --- a/test-setup.js +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint-disable @typescript-eslint/no-var-requires, import/no-extraneous-dependencies */ -require('chai-snapshot-matcher') - -const chaiQuantifiers = require('chai-quantifiers') -const chai = require('chai') -const sinonChai = require('sinon-chai') -const chaiSubset = require('chai-subset') - -chai.use(sinonChai) -chai.use(chaiQuantifiers) -chai.use(chaiSubset)