mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 09:17:43 +03:00
@daml/react: Make the test suite invokable by yarn test (#4646)
Unfortunately, we need to work around some bazel issues which lead to confliciting versions of react in our tests. This workaround cannot be used the tests are invoked via `yarn test`. Thus, we only use it when we the tests from bazel. We use the existence of the environment variable `TEST_WORKSPACE` as a proxy for whether we run from bazel. CHANGELOG_BEGIN CHANGELOG_END
This commit is contained in:
parent
64dbc52d43
commit
0284fd04b4
@ -1,6 +1,29 @@
|
||||
// Copyright (c) 2020 The DAML Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const moduleNameMapper = {
|
||||
'^@daml/types$': '../daml-types',
|
||||
'^@daml/ledger$': '../daml-ledger',
|
||||
// $1 used for @daml/react/ledgerStore
|
||||
'^@daml/react(.*)$': '../daml-react$1'
|
||||
};
|
||||
|
||||
// Bazel workaround for:
|
||||
//
|
||||
// Invalid hook call. Hooks can only be called inside of the body of a function component.
|
||||
//
|
||||
// By default the test-case loads `react/cjs/react.development.js` and
|
||||
// fails with the above error. A similar issue with `ts_devserver` suggests
|
||||
// that `rules_nodejs` bundles conflicting versions of react in some of the
|
||||
// artifacts. See https://github.com/bazelbuild/rules_nodejs/issues/1383 .
|
||||
//
|
||||
// We do not want to use this workaround when invoking the test with
|
||||
// `yarn test`. We us the existence of the environment variable
|
||||
// `TEST_WORKSPACE` as a proxy for whether the test was invoked from bazel.
|
||||
if (process.env.TEST_WORKSPACE !== undefined) {
|
||||
moduleNameMapper['^react$'] = '<rootDir>/../../../node_modules/react/umd/react.development.js';
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
testEnvironment: "node",
|
||||
testMatch: [
|
||||
@ -11,20 +34,5 @@ module.exports = {
|
||||
"^.+\\.(ts|tsx)$": "ts-jest",
|
||||
"^.+\\.(js|jsx)$": "babel-jest"
|
||||
},
|
||||
moduleNameMapper: {
|
||||
// Workaround for:
|
||||
//
|
||||
// Invalid hook call. Hooks can only be called inside of the body of a function component.
|
||||
//
|
||||
// By default the test-case loads `react/cjs/react.development.js` and
|
||||
// fails with the above error. A similar issue with `ts_devserver` suggests
|
||||
// that `rules_nodejs` bundles conflicting versions of react in some of the
|
||||
// artifacts. See https://github.com/bazelbuild/rules_nodejs/issues/1383 .
|
||||
'^react$': '<rootDir>/../../../node_modules/react/umd/react.development.js',
|
||||
'^@daml/types$': '../daml-types',
|
||||
'^@daml/ledger$': '../daml-ledger',
|
||||
// $1 used for @daml/react/ledgerStore
|
||||
'^@daml/react(.*)$': '../daml-react$1'
|
||||
}
|
||||
moduleNameMapper,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user