-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mock Service Worker - msw (#513)
* Add msw * PR feedback * Support Intellij project users * PR review * PR review * PR review * PR review * PR review * PR review * PR review * PR review * PR review * PR review * Wrap up * Add msw to schema & types --------- Co-authored-by: Lars Kappert <[email protected]>
- Loading branch information
Showing
14 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Mock Service Worker (2.2.0). | ||
* @see https://github.com/mswjs/msw | ||
* - Please do NOT modify this file. | ||
* - Please do NOT serve this file on production. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './handlers'; |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './handlers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@fixtures/msw", | ||
"version": "*", | ||
"knip": { | ||
"msw": true | ||
}, | ||
"devDependencies": { | ||
"msw": "*" | ||
}, | ||
"msw": { | ||
"workerDirectory": "bob" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { join } from '../../util/path.js'; | ||
import { basename } from '../../util/path.js'; | ||
import { hasDependency } from '../../util/plugin.js'; | ||
import { toEntryPattern } from '../../util/protocols.js'; | ||
import type { MSWConfig } from './types.js'; | ||
import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js'; | ||
|
||
// https://mswjs.io/docs/integrations/browser | ||
|
||
const NAME = 'Mock Service Worker'; | ||
|
||
const ENABLERS = ['msw']; | ||
|
||
const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(dependencies, ENABLERS); | ||
|
||
const CONFIG_FILE_PATTERNS = ['package.json']; | ||
|
||
const ENTRY_FILE_PATTERNS = ['mockServiceWorker.js']; | ||
|
||
const findDependencies: GenericPluginCallback = async (configFilePath, options) => { | ||
const { manifest } = options; | ||
|
||
// @ts-expect-error Bug in TS? (see other plugins with `await load`) | ||
const localConfig: MSWConfig | undefined = basename(configFilePath) === 'package.json' ? manifest.msw : undefined; | ||
|
||
const workerDirectory = localConfig?.workerDirectory ?? '.'; | ||
|
||
return ENTRY_FILE_PATTERNS.map(pattern => toEntryPattern(join(workerDirectory, pattern))); | ||
}; | ||
|
||
export default { | ||
NAME, | ||
ENABLERS, | ||
isEnabled, | ||
CONFIG_FILE_PATTERNS, | ||
ENTRY_FILE_PATTERNS, | ||
findDependencies, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface MSWConfig { | ||
workerDirectory?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import assert from 'node:assert/strict'; | ||
import test from 'node:test'; | ||
import { main } from '../../src/index.js'; | ||
import { resolve } from '../../src/util/path.js'; | ||
import baseArguments from '../helpers/baseArguments.js'; | ||
import baseCounters from '../helpers/baseCounters.js'; | ||
|
||
const cwd = resolve('fixtures/plugins/msw'); | ||
|
||
test('Should not see the msw files in issues', async () => { | ||
const { counters } = await main({ | ||
...baseArguments, | ||
cwd, | ||
isStrict: true, | ||
}); | ||
|
||
assert.deepEqual(counters, { | ||
...baseCounters, | ||
files: 4, | ||
devDependencies: 1, | ||
total: 5, | ||
processed: 5, | ||
}); | ||
}); |