wallabyjs / public

Repository for Wallaby.js questions and issues
http://wallabyjs.com
760 stars 45 forks source link

Running alternative setups in specific subfolders - Where to place wallaby.config(s)? #2801

Closed chrismilleruk closed 3 years ago

chrismilleruk commented 3 years ago

Issue description or question

Project setup & background

https://github.com/chrismilleruk/amplify-wallaby

This vanilla project structure is essentially a Create React App with an amplify folder as created with the Amplify CLI via amplify init.

I believe the Create React App is fairly standard in package.json and ./src and works with Wallaby using autodetect. The CRA has not been ejected.

Lambda functions can be added to ./amplify/backend/function/<fnName> with Amplify CLI Function via amplify add function.

I have added some basic tests to the hello world lambda function and added TS support via ts-jest. Those tests run OK with the following code: cd amplify/backend/function/amplifyFunction1 && jest --preset ts-jest --watch && cd - or npm run test:functions

Issue experienced

I'm struggling to configure Wallaby in a way that works for both the CRA tests and the ts-node Lambda Function tests.

In an ideal world, there would be a single wallaby config which covers all tests so we don't break flow by switching configs. Since wallaby doesn't necessarily run the standard suites, a multi-config setup seems like if could be theoretically possible?

In 2nd place, having a single wallaby config to cover everything in ./amplify/backend/function so that it could trigger all the lambda function tests at once. I attempted this with ./wallaby.config.amplify.backend.js

Finally, one wallaby config per function would at least allow the reduced feedback loop when working on a single lambda function. This approach is in ./amplify/backend/function/amplifyFunction1/wallaby.config.js.

I've read most of the config pages on https://wallabyjs.com/docs/ but have been unable to get any of the above approaches working. I'm in danger of spending more time on setup than I would ever recover with faster feedback loops so I would appreciate some help / pointers for next steps.

Wallaby diagnostics report

./wallaby.config.amplify.backend.js

0 failing tests, 0 passing  ​Launch Coverage & Test Explorer​ | ​Search Tests​

test is not defined 
  ​​​​​at Object.<anonymous> ​​​​​​amplify/backend/function/amplifyFunction1/lib/index.test.js:3:0​

test is not defined 
  ​​​​​at Object.<anonymous> ​​​​​​amplify/backend/function/amplifyFunction1/lib/index.typed.test.ts:3:0​
Diagnostics from `./wallaby.config.amplify.backend.js` ``` { editorVersion: '1.60.1', pluginVersion: '1.0.313', editorType: 'VSCode', osVersion: 'darwin 20.6.0', nodeVersion: 'v16.6.2', coreVersion: '1.0.1145', config: { files: [ { pattern: 'amplify/backend/function/**/*.{js,jsx,ts,tsx}', ignore: false, trigger: true, load: true, instrument: true, order: 1 }, { pattern: 'amplify/backend/function/**/*.{spec,test}.{js,jsx,ts,tsx}', ignore: true, trigger: true, load: true, instrument: true } ], tests: [ { pattern: 'amplify/backend/function/**/*.{spec,test}.{js,jsx,ts,tsx}', ignore: false, trigger: true, load: true, test: true, order: 2 } ], env: { type: 'node', params: {}, runner: '/usr/local/bin/node', viewportSize: { width: 800, height: 600 }, options: { width: 800, height: 600 }, bundle: true }, compilers: { '**/*.ts?(x)': [Function (anonymous)], '**/*.?(lit)coffee?(.md)': [Function (anonymous)] }, testRunner: { config: 'jest.config.amplify.backend.js' }, diagnostics: {}, filesWithNoCoverageCalculated: [], runAllTestsInAffectedTestFile: false, updateNoMoreThanOneSnapshotPerTestFileRun: false, addModifiedTestFileToExclusiveTestRun: true, preprocessors: {}, maxConsoleMessagesPerTest: 100, autoConsoleLog: true, delays: { run: 0, edit: 100, update: 0 }, workers: { initial: 0, regular: 0, recycle: false }, teardown: undefined, hints: { ignoreCoverage: '__REGEXP /ignore coverage|istanbul ignore/', ignoreCoverageForFile: '__REGEXP /ignore file coverage/', commentAutoLog: '?', testFileSelection: { include: '__REGEXP /file\\.only/', exclude: '__REGEXP /file\\.skip/' } }, automaticTestFileSelection: true, runSelectedTestsOnly: false, mapConsoleMessagesStackTrace: false, extensions: {}, reportUnhandledPromises: true, testFramework: { version: 'mocha@2.1.0', configurator: 'mocha@2.1.0', reporter: 'mocha@2.1.0', starter: 'mocha@2.1.0' }, slowTestThreshold: 75, lowCoverageThreshold: 80, loose: undefined, symlinkNodeModules: undefined, configCode: 'module.exports = function (wallaby) {\n' + ' return {\n' + ' files: [\n' + ' "amplify/backend/function/**/*.{js,jsx,ts,tsx}",\n' + ' {\n' + ' pattern: "amplify/backend/function/**/*.{spec,test}.{js,jsx,ts,tsx}",\n' + ' ignore: true,\n' + ' },\n' + ' ],\n' + ' tests: ["amplify/backend/function/**/*.{spec,test}.{js,jsx,ts,tsx}"],\n' + ' env: {\n' + ' type: "node",\n' + ' },\n' + ' compilers: {\n' + ' "**/*.ts?(x)": wallaby.compilers.typeScript({\n' + ' module: "commonjs",\n' + ' jsx: "React",\n' + ' isolatedModules: true,\n' + ' outDir: "./src",\n' + ' }),\n' + ' },\n' + ' testRunner: {\n' + ' config: "jest.config.amplify.backend.js"\n' + ' }\n' + ' };\n' + '};\n' }, packageJSON: { dependencies: { '@aws-amplify/ui-react': '^1.2.15', '@testing-library/jest-dom': '^5.14.1', '@testing-library/react': '^12.1.0', '@testing-library/user-event': '^13.2.1', 'aws-amplify': '^4.2.9', react: '^17.0.2', 'react-dom': '^17.0.2', 'react-scripts': '4.0.3', 'web-vitals': '^2.1.0' }, devDependencies: { '@types/jest': '^26.0.14', 'ts-jest': '^26.5.6', typescript: '^4.4.3' } }, fs: { numberOfFiles: 7 }, debug: [ '2021-09-19T23:08:27.027Z project Wallaby Node version: v16.6.2\n', '2021-09-19T23:08:27.027Z project Wallaby config: /dev/scratch/amplifyapp/wallaby.config.amplify.backend.js\n', '2021-09-19T23:08:27.086Z project File cache: /.vscode/extensions/wallabyjs.wallaby-vscode-1.0.313/projects/4646cbae719f41d3\n', '2021-09-19T23:08:27.265Z uiService Listening port 51235\n', '2021-09-19T23:08:27.283Z workers Parallelism for initial run: 6, for regular run: 3\n', '2021-09-19T23:08:27.283Z workers Starting run worker instance #0\n', '2021-09-19T23:08:27.284Z workers Starting run worker instance #1\n', '2021-09-19T23:08:27.284Z workers Starting run worker instance #2\n', '2021-09-19T23:08:27.284Z workers Starting run worker instance #3\n', '2021-09-19T23:08:27.284Z workers Starting run worker instance #4\n', '2021-09-19T23:08:27.284Z workers Starting run worker instance #5\n', '2021-09-19T23:08:27.285Z workers Web server is listening at 52846\n', '2021-09-19T23:08:27.326Z project File cache requires some updates, waiting required files from IDE\n', '2021-09-19T23:08:27.553Z workers Started run worker instance (delayed) #1\n', '2021-09-19T23:08:27.554Z workers Started run worker instance (delayed) #0\n', '2021-09-19T23:08:27.554Z workers Started run worker instance (delayed) #2\n', '2021-09-19T23:08:27.558Z workers Started run worker instance (delayed) #3\n', '2021-09-19T23:08:27.578Z workers Started run worker instance (delayed) #5\n', '2021-09-19T23:08:27.603Z workers Started run worker instance (delayed) #4\n', '2021-09-19T23:08:27.907Z project Stopping process pool\n', '2021-09-19T23:08:27.909Z project Test run started; run priority: 3\n', '2021-09-19T23:08:27.912Z project Running all tests\n', '2021-09-19T23:08:27.917Z workers Starting test run, priority: 3\n', '2021-09-19T23:08:27.917Z workers Distributing tests between 6 workers\n', '2021-09-19T23:08:27.918Z workers Running tests in parallel\n', '2021-09-19T23:08:27.919Z nodeRunner Starting sandbox [worker #0, session #vdppu]\n', '2021-09-19T23:08:27.919Z nodeRunner Starting sandbox [worker #1, session #bmoje]\n', '2021-09-19T23:08:27.920Z nodeRunner Preparing sandbox [worker #0, session #vdppu]\n', '2021-09-19T23:08:27.920Z nodeRunner Preparing sandbox [worker #1, session #bmoje]\n', '2021-09-19T23:08:27.920Z nodeRunner Prepared sandbox [worker #0, session #vdppu]\n', '2021-09-19T23:08:27.920Z nodeRunner Prepared sandbox [worker #1, session #bmoje]\n', '2021-09-19T23:08:27.920Z workers [worker #0, session #vdppu] Running tests in sandbox\n', '2021-09-19T23:08:27.922Z workers [worker #1, session #bmoje] Running tests in sandbox\n', '2021-09-19T23:08:28.123Z workers Sandbox (active) [vdppu] error: test is not defined\n', '2021-09-19T23:08:28.127Z workers Sandbox (active) [bmoje] error: test is not defined\n', '2021-09-19T23:08:28.228Z workers [vdppu] Run 0 test(s), skipped 0 test(s)\n', '2021-09-19T23:08:28.229Z workers [bmoje] Run 0 test(s), skipped 0 test(s)\n', '2021-09-19T23:08:28.231Z workers [bmoje] Sandbox is responsive, closing it\n', '2021-09-19T23:08:28.232Z workers [vdppu] Sandbox is responsive, closing it\n', '2021-09-19T23:08:28.232Z workers Merging parallel test run results\n', '2021-09-19T23:08:28.233Z project Test run finished\n', '2021-09-19T23:08:28.233Z project Processed console.log entries\n', '2021-09-19T23:08:28.233Z project Processed loading sequences\n', '2021-09-19T23:08:28.233Z project Processed executed tests\n', '2021-09-19T23:08:28.234Z project Processed code coverage\n', '2021-09-19T23:08:28.241Z project Test run result processed and sent to IDE\n' ] } ```

./amplify/backend/function/amplifyFunction1/wallaby.config.js

‌0 failing tests, 2 passing  ​Launch Coverage & Test Explorer​ | ​Search Tests​

Cannot use import statement outside a module 
  ​​​​​at ​​​​​​lib/index.typed.test.ts:1​
Diagnostics from `./amplify/backend/function/amplifyFunction1/wallaby.config.js` ``` { editorVersion: '1.60.1', pluginVersion: '1.0.313', editorType: 'VSCode', osVersion: 'darwin 20.6.0', nodeVersion: 'v16.6.2', coreVersion: '1.0.1145', config: { env: { type: 'node', params: {}, runner: '/usr/local/bin/node', viewportSize: { width: 800, height: 600 }, options: { width: 800, height: 600 }, bundle: true }, compilers: { '**/*.ts?(x)': [Function (anonymous)] }, testFramework: { version: 'jest@24.8.0', configurator: 'jest@24.8.0', reporter: 'jest@24.8.0', starter: 'jest@24.8.0', autoDetected: true }, diagnostics: { jest: { config: { configs: [ { automock: false, cache: true, cacheDirectory: '/private/var/folders/mv/xpp32cys7lnddv91021y1xpw0000gp/T/jest_dy', clearMocks: false, coveragePathIgnorePatterns: [ '/node_modules/' ], cwd: '/dev/scratch/amplifyapp/amplify/backend/function/amplifyFunction1', dependencyExtractor: undefined, detectLeaks: undefined, detectOpenHandles: undefined, displayName: undefined, errorOnDeprecated: false, extraGlobals: [], filter: undefined, forceCoverageMatch: [], globalSetup: undefined, globalTeardown: undefined, globals: {}, haste: { computeSha1: false, throwOnModuleCollision: false }, injectGlobals: true, moduleDirectories: [ 'node_modules' ], moduleFileExtensions: [ 'js', 'json', 'jsx', 'ts', 'tsx', 'node' ], moduleLoader: undefined, moduleNameMapper: [], modulePathIgnorePatterns: [], modulePaths: undefined, name: 'bd246c19caf06d3de348d6bb87deb82b', prettierPath: 'prettier', resetMocks: false, resetModules: false, resolver: undefined, restoreMocks: false, rootDir: '/dev/scratch/amplifyapp/amplify/backend/function/amplifyFunction1', roots: [ '/dev/scratch/amplifyapp/amplify/backend/function/amplifyFunction1' ], runner: 'jest-runner', setupFiles: [], setupFilesAfterEnv: [], skipFilter: false, skipNodeResolution: undefined, slowTestThreshold: 5, snapshotResolver: undefined, snapshotSerializers: [], testEnvironment: '/dev/scratch/amplifyapp/node_modules/jest-environment-jsdom/build/index.js', testEnvironmentOptions: {}, testLocationInResults: false, testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)' ], testPathIgnorePatterns: [ '/node_modules/' ], testRegex: [], testRunner: '/dev/scratch/amplifyapp/node_modules/jest-jasmine2/build/index.js', testURL: 'http://localhost', timers: 'real', transform: [ [ '\\.[jt]sx?$', '/dev/scratch/amplifyapp/node_modules/jest-config/node_modules/babel-jest/build/index.js', {} ] ], transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ], unmockedModulePathPatterns: undefined, watchPathIgnorePatterns: [] } ], globalConfig: { bail: 0, changedFilesWithAncestor: false, changedSince: undefined, collectCoverage: false, collectCoverageFrom: [], collectCoverageOnlyFrom: undefined, coverageDirectory: '/dev/scratch/amplifyapp/amplify/backend/function/amplifyFunction1/coverage', coverageProvider: 'babel', coverageReporters: [ 'json', 'text', 'lcov', 'clover' ], coverageThreshold: undefined, detectLeaks: undefined, detectOpenHandles: undefined, enabledTestsMap: undefined, errorOnDeprecated: false, expand: false, filter: undefined, findRelatedTests: false, forceExit: false, globalSetup: undefined, globalTeardown: undefined, json: false, lastCommit: false, listTests: undefined, logHeapUsage: false, maxConcurrency: 5, maxWorkers: 7, noSCM: undefined, noStackTrace: false, nonFlagArgs: undefined, notify: false, notifyMode: 'failure-change', onlyChanged: false, onlyFailures: false, outputFile: undefined, passWithNoTests: undefined, projects: [], replname: undefined, reporters: undefined, rootDir: '/dev/scratch/amplifyapp/amplify/backend/function/amplifyFunction1', runTestsByPath: false, silent: undefined, skipFilter: false, testFailureExitCode: 1, testNamePattern: undefined, testPathPattern: '', testResultsProcessor: undefined, testSequencer: '/dev/scratch/amplifyapp/node_modules/@jest/test-sequencer/build/index.js', testTimeout: undefined, updateSnapshot: 'new', useStderr: false, verbose: undefined, watch: false, watchAll: false, watchPlugins: undefined, watchman: true }, hasDeprecationWarnings: false, wallaby: { roots: [], watchPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/' ], testPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/' ], testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)' ], testRegex: [] } } } }, filesWithCoverageCalculated: [], filesWithNoCoverageCalculated: [], globalSetup: false, micromatch: true, files: [ { pattern: '/node_modules/', regexp: /\/node_modules\//, ignore: true, trigger: true, load: true, instrument: true }, { pattern: '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/', regexp: /\.\/dist\/|\.\/build\/|\.\/coverage\/|\.\/git\/|\/\..+\//, ignore: true, trigger: true, load: true, instrument: true }, { pattern: '**/**', ignore: false, trigger: true, load: true, instrument: true, order: 1 }, { pattern: '**/__tests__/**/*.[jt]s?(x)', ignore: true, trigger: true, load: true }, { pattern: '**/?(*.)+(spec|test).[tj]s?(x)', ignore: true, trigger: true, load: true } ], tests: [ { pattern: '/node_modules/', regexp: /\/node_modules\//, ignore: true, trigger: true, load: true, test: true }, { pattern: '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/', regexp: /\.\/dist\/|\.\/build\/|\.\/coverage\/|\.\/git\/|\/\..+\//, ignore: true, trigger: true, load: true, test: true }, { pattern: '**/__tests__/**/*.[jt]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 2 }, { pattern: '**/?(*.)+(spec|test).[tj]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 3 } ], runAllTestsInAffectedTestFile: false, updateNoMoreThanOneSnapshotPerTestFileRun: false, addModifiedTestFileToExclusiveTestRun: true, preprocessors: {}, maxConsoleMessagesPerTest: 100, autoConsoleLog: true, delays: { run: 0, edit: 100, update: 0 }, workers: { initial: 0, regular: 0, recycle: false }, teardown: undefined, hints: { ignoreCoverage: '__REGEXP /ignore coverage|istanbul ignore/', ignoreCoverageForFile: '__REGEXP /ignore file coverage/', commentAutoLog: '?', testFileSelection: { include: '__REGEXP /file\\.only/', exclude: '__REGEXP /file\\.skip/' } }, automaticTestFileSelection: true, runSelectedTestsOnly: false, mapConsoleMessagesStackTrace: false, extensions: {}, reportUnhandledPromises: true, slowTestThreshold: 75, lowCoverageThreshold: 80, loose: true, configCode: 'module.exports = function (wallaby) {\n' + ' return {\n' + ' autoDetect: true,\n' + ' // files: [\n' + ' // "**/*.{js,jsx,ts,tsx}",\n' + ' // {\n' + ' // pattern: "**/*.{spec,test}.{js,jsx,ts,tsx}",\n' + ' // ignore: true,\n' + ' // },\n' + ' // ],\n' + ' // tests: ["**/*.{spec,test}.{js,jsx,ts,tsx}"],\n' + ' env: {\n' + ' type: "node",\n' + ' },\n' + ' compilers: {\n' + ' "**/*.ts?(x)": wallaby.compilers.typeScript({\n' + " typescript: require('typescript'),\n" + ' module: "commonjs",\n' + ' target: "es2020",\n' + ' isolatedModules: true,\n' + ' useStandardDefaults: true\n' + ' }),\n' + ' },\n' + " testFramework: 'jest'\n" + ' };\n' + '};\n' }, fs: { numberOfFiles: 13 }, debug: [ '2021-09-19T23:10:30.059Z angular/cli config Angular CLI not found.\n', '2021-09-19T23:10:30.213Z jest/config Detected Jest.\n', '2021-09-19T23:10:30.214Z jest/config Configured Jest.\n', '2021-09-19T23:10:30.215Z project Wallaby Node version: v16.6.2\n', '2021-09-19T23:10:30.215Z project Wallaby config: /dev/scratch/amplifyapp/amplify/backend/function/amplifyFunction1/wallaby.config.js\n', '2021-09-19T23:10:30.283Z project File cache: /.vscode/extensions/wallabyjs.wallaby-vscode-1.0.313/projects/6fbe8f4dfb16f0d0\n', '2021-09-19T23:10:30.420Z uiService Listening port 51235\n', '2021-09-19T23:10:30.434Z workers Parallelism for initial run: 6, for regular run: 3\n', '2021-09-19T23:10:30.435Z workers Starting run worker instance #0\n', '2021-09-19T23:10:30.435Z workers Starting run worker instance #1\n', '2021-09-19T23:10:30.435Z workers Starting run worker instance #2\n', '2021-09-19T23:10:30.435Z workers Starting run worker instance #3\n', '2021-09-19T23:10:30.435Z workers Starting run worker instance #4\n', '2021-09-19T23:10:30.435Z workers Starting run worker instance #5\n', '2021-09-19T23:10:30.435Z workers Web server is listening at 52890\n', '2021-09-19T23:10:30.435Z project File cache requires some updates, waiting required files from IDE\n', '2021-09-19T23:10:30.479Z project Stopping process pool\n', '2021-09-19T23:10:30.480Z project Test run started; run priority: 3\n', '2021-09-19T23:10:30.481Z project Running all tests\n', '2021-09-19T23:10:30.486Z workers Starting test run, priority: 3\n', '2021-09-19T23:10:30.486Z workers Distributing tests between 6 workers\n', '2021-09-19T23:10:30.486Z workers Running tests in parallel\n', '2021-09-19T23:10:30.487Z nodeRunner Starting sandbox [worker #0, session #16f8o]\n', '2021-09-19T23:10:30.487Z nodeRunner Starting sandbox [worker #1, session #fvyv7]\n', '2021-09-19T23:10:30.487Z nodeRunner Preparing sandbox [worker #0, session #16f8o]\n', '2021-09-19T23:10:30.487Z nodeRunner Preparing sandbox [worker #1, session #fvyv7]\n', '2021-09-19T23:10:30.618Z workers Started run worker instance (delayed) #0\n', '2021-09-19T23:10:30.618Z nodeRunner Prepared sandbox [worker #0, session #16f8o]\n', '2021-09-19T23:10:30.619Z workers [worker #0, session #16f8o] Running tests in sandbox\n', '2021-09-19T23:10:30.620Z workers Started run worker instance (delayed) #1\n', '2021-09-19T23:10:30.621Z nodeRunner Prepared sandbox [worker #1, session #fvyv7]\n', '2021-09-19T23:10:30.621Z workers [worker #1, session #fvyv7] Running tests in sandbox\n', '2021-09-19T23:10:30.624Z workers Started run worker instance (delayed) #2\n', '2021-09-19T23:10:30.632Z workers Started run worker instance (delayed) #3\n', '2021-09-19T23:10:30.636Z workers Started run worker instance (delayed) #4\n', '2021-09-19T23:10:30.638Z workers Started run worker instance (delayed) #5\n', '2021-09-19T23:10:33.331Z workers Scheduling Jest Test Run (fvyv7): 2021-09-19T23:10:31.238Z\n', '2021-09-19T23:10:33.336Z workers Sandbox (active) [fvyv7] error: Cannot use import statement outside a module\n', '2021-09-19T23:10:33.339Z workers [fvyv7] Run 0 test(s), skipped 0 test(s)\n', '2021-09-19T23:10:33.340Z workers Jest Test Run Complete (fvyv7): 2021-09-19T23:10:33.329Z\n', '2021-09-19T23:10:33.341Z workers [fvyv7] Sandbox is responsive, closing it\n', '2021-09-19T23:10:33.351Z workers Scheduling Jest Test Run (16f8o): 2021-09-19T23:10:31.238Z\n', '2021-09-19T23:10:33.354Z workers [16f8o] Loaded unknown number of test(s)\n', '2021-09-19T23:10:33.354Z workers [16f8o] Test executed: index handler is a function\n', '2021-09-19T23:10:33.355Z workers [16f8o] Test executed: call handler with built-in test event\n', '2021-09-19T23:10:33.356Z workers [16f8o] Run 2 test(s), skipped 0 test(s)\n', '2021-09-19T23:10:33.356Z workers Jest Test Run Complete (16f8o): 2021-09-19T23:10:33.349Z\n', '2021-09-19T23:10:33.357Z workers [16f8o] Sandbox is responsive, closing it\n', '2021-09-19T23:10:33.358Z workers Merging parallel test run results\n', '2021-09-19T23:10:33.358Z project Test run finished\n', '2021-09-19T23:10:33.359Z project Processed console.log entries\n', '2021-09-19T23:10:33.359Z project Processed loading sequences\n', '2021-09-19T23:10:33.359Z project Processed executed tests\n', '2021-09-19T23:10:33.360Z project Processed code coverage\n', '2021-09-19T23:10:33.367Z project Test run result processed and sent to IDE\n' ] } ```
ArtemGovorov commented 3 years ago

Thanks for providing the sample repo. Most of your question/issue is not Wallaby specific (you need to configure Jest and Wallaby should just work with the working Jest config).

Wallaby autodetect supports selecting subfolders (with Jest configured), so if you can run Jest in a folder with npx jest, then Wallaby can run it too (without any additional Wallaby config files).

Your /amplify/backend/function/amplifyFunction1 is almost good in that regard, it just has an invalid amplify/backend/function/amplifyFunction1/jest.config.js (the file doesn't export the config). After you add

+module.exports = config;

at the end of the file, you will be able to run npx jest in the folder /amplify/backend/function/amplifyFunction1, and Wallaby autodetect for that folder will also work for you (Wallaby.js: Select Configuration - then select amplify/backend/function/amplifyFunction1/):

w2801

In an ideal world, there would be a single wallaby config which covers all tests so we don't break flow by switching configs. In 2nd place, having a single wallaby config to cover everything in ./amplify/backend/function so that it could trigger all the lambda function tests at once. I attempted this with ./wallaby.config.amplify.backend.js

As I have mentioned above, if you can run Jest in any folder with npx jest, then Wallaby can run it too (without any additional Wallaby config files). So the same way as for the amplifyFunction1 subfolder above, you will just need to add a working jest config file into the amplify/backend/function/ folder and select the folder using Wallaby command. The same way, if you find a way to add a working Jest config in your repo's root, so that when you run npx jest in your repo's root - it runs all of your tests, then Wallaby autodetect for the root will also run that config and will run all of your tests.

You may use Jest multi project setting to specify multiple projects to run tests in in a single Jest config. For example, if you copy/paste your amplifyFunction1 folder so that you have multiple functions to test, and then add the following file amplify/backend/jest.config.js

module.exports = {
    projects: [
      '<rootDir>/function/*'
    ]
}

then cd amplify/backend/ and npx jest, all of your function projects will run with Jest (and Wallaby too):

w28011

Creating your Jest config for the root with CRA and some other subfolder to run all tests is a bit tricker (because CRA gets some custom Jest configuration resolved) but should be possible too:

Now npx jest in your repo's root (as well as Wallaby autodetect for your repo's root) should work too:

w28012

Hope it helps and answers your question. I have created the pull request with Jest configs and other changes mentioned in the response: https://github.com/chrismilleruk/amplify-wallaby/pull/1.

chrismilleruk commented 3 years ago

Thanks for your help and quick response!!