Sha256: 53d7cbc2fa0edaeb68b400860fc3b621e6eb0031d013d124687906941ab1fd9f

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

const index = require("../../package/index")

jest.mock("../../package/utils/helpers", () => {
  const original = jest.requireActual("../../package/utils/helpers")
  const moduleExists = () => false
  return {
    ...original,
    moduleExists
  }
})

describe("index", () => {
  test("exports webpack-merge v5 functions", () => {
    expect(index.merge).toBeInstanceOf(Function)
    expect(index.mergeWithRules).toBeInstanceOf(Function)
    expect(index.mergeWithCustomize).toBeInstanceOf(Function)
  })

  test("webpackConfig returns an immutable object", () => {
    const { generateWebpackConfig } = require("../../package/index")

    const webpackConfig1 = generateWebpackConfig()
    const webpackConfig2 = generateWebpackConfig()

    webpackConfig1.newKey = "new value"
    webpackConfig1.output.path = "new path"

    expect(webpackConfig2).not.toHaveProperty("newKey")
    expect(webpackConfig2.output.path).not.toBe("new value")
  })

  test("webpackConfig merges extra config", () => {
    const { generateWebpackConfig } = require("../../package/index")

    const webpackConfig = generateWebpackConfig({
      newKey: "new value",
      output: {
        path: "new path"
      }
    })

    expect(webpackConfig).toHaveProperty("newKey", "new value")
    expect(webpackConfig).toHaveProperty("output.path", "new path")
    expect(webpackConfig).toHaveProperty("output.publicPath", "/packs/")
  })

  test("webpackConfig errors if multiple configs are provided", () => {
    const { generateWebpackConfig } = require("../../package/index")

    expect(() => generateWebpackConfig({}, {})).toThrow(
      "use webpack-merge to merge configs before passing them to Shakapacker"
    )
  })
})

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shakapacker-8.1.0 test/package/index.test.js
shakapacker-8.0.2 test/package/index.test.js