Skip to content

Commit

Permalink
mock moduleExists now that we've mocked css-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Judahmeek committed Aug 29, 2024
1 parent 624c63b commit 53d817f
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 5 deletions.
9 changes: 9 additions & 0 deletions test/package/development.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ const { chdirTestApp, resetEnv } = require("../helpers")
const rootPath = process.cwd()
chdirTestApp()

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

describe("Development environment", () => {
beforeEach(() => jest.resetModules() && resetEnv())
afterAll(() => process.chdir(rootPath))
Expand Down
9 changes: 9 additions & 0 deletions test/package/environments/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ chdirTestApp()
const baseConfig = require("../../../package/environments/base")
const config = require("../../../package/config")

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

describe("Base config", () => {
beforeEach(() => jest.resetModules() && resetEnv())
afterAll(() => process.chdir(rootPath))
Expand Down
9 changes: 9 additions & 0 deletions test/package/environments/development.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ const { chdirTestApp, resetEnv } = require("../../helpers")
const rootPath = process.cwd()
chdirTestApp()

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

describe("Development specific config", () => {
beforeEach(() => {
jest.resetModules()
Expand Down
9 changes: 9 additions & 0 deletions test/package/environments/production.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ const { chdirTestApp, resetEnv } = require("../../helpers")
const rootPath = process.cwd()
chdirTestApp()

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

describe("Production specific config", () => {
beforeEach(() => {
jest.resetModules()
Expand Down
9 changes: 9 additions & 0 deletions test/package/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
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)
Expand Down
9 changes: 9 additions & 0 deletions test/package/production.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ const { chdirTestApp } = require("../helpers")
const rootPath = process.cwd()
chdirTestApp()

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

describe("Production environment", () => {
afterAll(() => process.chdir(rootPath))

Expand Down
9 changes: 9 additions & 0 deletions test/package/rules/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const rules = require("../../../package/rules/index")

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

describe("index", () => {
test("rule tests are regexes", () => {
rules.forEach((rule) => expect(rule.test instanceof RegExp).toBe(true))
Expand Down
2 changes: 0 additions & 2 deletions test/package/rules/sass.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ jest.mock("../../../package/utils/helpers", () => {
const canProcess = (rule, fn) => {
return fn("This path was mocked")
}
const moduleExists = () => true
const packageMajorVersion = () => "15"
return {
...original,
canProcess,
moduleExists,
packageMajorVersion
}
})
Expand Down
4 changes: 1 addition & 3 deletions test/package/rules/sass1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ jest.mock("../../../package/utils/helpers", () => {
const canProcess = (rule, fn) => {
return fn("This path was mocked")
}
const moduleExists = () => true
return {
...original,
canProcess,
moduleExists
canProcess
}
})

Expand Down
9 changes: 9 additions & 0 deletions test/package/staging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ const { chdirTestApp } = require("../helpers")
const rootPath = process.cwd()
chdirTestApp()

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

describe("Custom environment", () => {
afterAll(() => process.chdir(rootPath))

Expand Down
9 changes: 9 additions & 0 deletions test/package/test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ const { chdirTestApp } = require("../helpers")
const rootPath = process.cwd()
chdirTestApp()

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

describe("Test environment", () => {
afterAll(() => process.chdir(rootPath))

Expand Down

0 comments on commit 53d817f

Please sign in to comment.