Jest testcase writing

Hello
I was trying to write testcases for the project which includes VTK JS. Project built in react. When I try to execute module which contains viewport it throws following error. It will be helpful if someonw can guide.

APP_PATH_HERE/node_modules/vtk.js/Sources/Rendering/OpenGL/glsl/vtkPolyDataVS.glsl:18
attribute vec4 vertexMC;
^^^^

SyntaxError: Unexpected identifier

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
  at Object.<anonymous> (node_modules/vtk.js/Sources/Rendering/OpenGL/PolyDataMapper/index.js:11:1)

Since you are depending on vtk.js sources, you need custom rules for importing glsl files. If you switch your import to @kitware/vtk.js/... that may simplify things for you.

Thank you for quick reply @Sebastien_Jourdain. But I have already added VTKRules in my webpack configuration
const vtkRules = require(‘vtk.js/Utilities/config/dependency.js’).webpack.core
.rules

Concatenating these rules. My app execution is working perfectly fine its just while I try running “jest testcases” using npm run test it fails. Do I need to follow anyother rule for the same.

After changing vtk.js to @kitware/vtk.js/… error still persist. Any guidance will be helpful

I tried to add
{ test: /.glsl$/i, loader: ‘shader-loader’ },
in webpack file but that too isn’t worked

My guess is that jest is using another execution/build path and therefore your build setup with the add-on rules is not happening at the test stage.

Completely blocked for writing test cases in React because of this error.
APP_PATH_HERE\node_modules\vtk.js\Sources\Rendering\OpenGL\glsl\vtkPolyDataVS.glsl:18
attribute vec4 vertexMC;
^^^^

SyntaxError: Unexpected identifier

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
  at Object.<anonymous> (node_modules/vtk.js/Sources/Rendering/OpenGL/PolyDataMapper/index.js:11:1)

Tried adding glsl-loader and @kitware both not working.

Like mentioned before, the issue is related to a loader which could be solved by not requiring any loader when using the ESM build of vtk.js. Which means you can not have a single import to vtk.js/Sources/*.