Skip to content

Commit

Permalink
Reorganize babel code and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
necolas committed Sep 26, 2024
1 parent a45687d commit 9049dc2
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 7 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
jest.autoMockOff();

const { transformSync } = require('@babel/core');
const rsdPlugin = require('../babel');
const babelReactStrictPlugin = require('react-strict-dom/babel');
const jsx = require('@babel/plugin-syntax-jsx');

function transform(source, pluginOptions = {}) {
Expand All @@ -21,7 +21,7 @@ function transform(source, pluginOptions = {}) {
parserOpts: {
flow: 'all'
},
plugins: [jsx, [rsdPlugin, { debug: false, ...pluginOptions }]]
plugins: [jsx, [babelReactStrictPlugin, { debug: false, ...pluginOptions }]]
}).code;
}

Expand Down
27 changes: 23 additions & 4 deletions packages/react-strict-dom/tools/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'use strict';

const babelConfig = require('./jest.babel.js');
const babelConfig = require('./jest/babelConfig.js');

module.exports = {
collectCoverageFrom: [
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports = {
enableGlobally: true
},
moduleNameMapper: {
'^react-strict-dom$': '<rootDir>/src/dom'
'^react-strict-dom$': '<rootDir>/src/dom/index.js'
},
rootDir: process.cwd(),
setupFiles: ['<rootDir>/tools/jest/setup.js'],
Expand All @@ -69,7 +69,7 @@ module.exports = {
enableGlobally: true
},
moduleNameMapper: {
'^react-strict-dom$': '<rootDir>/src/native'
'^react-strict-dom$': '<rootDir>/src/native/index.js'
},
rootDir: process.cwd(),
setupFiles: ['<rootDir>/tools/jest/setup.js'],
Expand All @@ -82,7 +82,26 @@ module.exports = {
'<rootDir>/tests/*-test.js',
'<rootDir>/tests/*-test.native.js'
],
testPathIgnorePatterns: ['<rootDir>/tests/babel-test.js'],
transform: {
'\\.[jt]sx?$': ['babel-jest', babelConfig()]
}
},
{
displayName: 'react-strict-dom (Node)',
fakeTimers: {
enableGlobally: true
},
moduleNameMapper: {
'^react-strict-dom/babel$': '<rootDir>/babel/index.js'
},
rootDir: process.cwd(),
setupFiles: ['<rootDir>/tools/jest/setup.js'],
snapshotFormat: {
printBasicPrototype: false
},
snapshotResolver: '<rootDir>/tools/jest/node-snapshot-resolver.js',
testEnvironment: 'node',
testMatch: ['<rootDir>/tests/*-test.node.js'],
transform: {
'\\.[jt]sx?$': ['babel-jest', babelConfig()]
}
Expand Down
42 changes: 42 additions & 0 deletions packages/react-strict-dom/tools/jest/node-snapshot-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const path = require('path');

/**
* Note that jest has a bug with custom snapshot resolvers that means
* "resolveTestPath" is incorrectly used to resolve test paths in the other
* jest "projects" that aren't using customer resolvers. Therefore, these
* custom resolvers are implemented in a way that allows them to function
* like the default resolver when resolving test paths.
*/

module.exports = {
resolveSnapshotPath: (testPath) => {
const snapshotPath = path.join(
path.join(path.dirname(testPath), '__snapshots__'),
path.basename(testPath) + '.snap-node'
);
return snapshotPath;
},

resolveTestPath: (snapshotPath) => {
const ext = path.extname(snapshotPath);
const testPath = path.join(
path.dirname(snapshotPath),
'..',
path.basename(snapshotPath, ext)
);
return testPath;
},

testPathForConsistencyCheck: path.join(
'consistency_check',
'__tests__',
'example.test.js'
)
};
2 changes: 1 addition & 1 deletion packages/react-strict-dom/tools/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const __dirname = import.meta.dirname;

const babelPlugin = babel({
babelHelpers: 'bundled',
configFile: path.resolve(__dirname, 'rollup.babel.mjs')
configFile: path.resolve(__dirname, 'rollup/babelConfig.mjs')
});

function ossLicensePlugin() {
Expand Down

0 comments on commit 9049dc2

Please sign in to comment.