jest-raw-loader

raw JSON →
1.0.1 verified Sat Apr 25 auth: no javascript maintenance

Jest transformer that imports files as raw strings, mimicking webpack-contrib/raw-loader for testing. Current stable version 1.0.1 (last release Jul 22, 2018; long-term maintenance unclear). It reads file content and returns it as a module exporting the string. Simple configuration via Jest's transform option. Unlike other loaders, it directly replaces file imports with their raw content, useful for testing components that import .graphql, .md, or .txt files. No updates since 2018, so may not support newer Jest versions.

error Cannot find module 'jest-raw-loader'
cause Package not installed or not in devDependencies.
fix
Run 'npm install --save-dev jest-raw-loader'
error TypeError: Transformer is not a function
cause Jest version incompatible (Jest 27+ expects async transformer).
fix
Upgrade to a compatible transformer or downgrade Jest to <=26.
error Invalid regular expression: /\\.graphql/: \ at end of pattern
cause Mis-escaped regex in JSON configuration.
fix
Use double backslashes: "\\.graphql$"
breaking jest-raw-loader may not work with Jest 27+ due to changes in transformer API (sync vs async).
fix Use a more maintained transformer like jest-transform-raw, or configure Jest custom transformer manually.
deprecated Package has not been updated since 2018; consider it in maintenance mode.
fix Evaluate alternatives if you need active maintenance or newer Jest support.
gotcha Transform configuration uses regex patterns, not globs. Backslashes in JSON must be double-escaped.
fix Use "\\.graphql$" (escaped backslash and dot) instead of ".graphql".
npm install jest-raw-loader
yarn add jest-raw-loader
pnpm add jest-raw-loader

Configure Jest to import .graphql and .md files as raw strings, then verify in a test.

// package.json
{
  "jest": {
    "transform": {
      "\\.graphql$": "jest-raw-loader",
      "\\.md$": "jest-raw-loader"
    }
  },
  "devDependencies": {
    "jest-raw-loader": "^1.0.1"
  }
}

// example.test.js
import graphqlContent from './schema.graphql';

test('returns raw string', () => {
  expect(typeof graphqlContent).toBe('string');
  expect(graphqlContent).toContain('type Query');
});