Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Commit 17b0456

Browse files
committed
Create a simple test for the macro
1 parent dfae12c commit 17b0456

6 files changed

+4653
-1
lines changed

Diff for: __snapshots__/require-context.macro.test.js.snap

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`require-context.macro macros 1. macros: 1. macros 1`] = `
4+
"
5+
import requireContext from './macro';
6+
7+
requireContext('../src/components', true, /.stories.js$/);
8+
9+
↓ ↓ ↓ ↓ ↓ ↓
10+
11+
\\"use strict\\";
12+
13+
__requireContext(__dirname, '../src/components', true, /.stories.js$/);
14+
"
15+
`;

Diff for: babel.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
module.exports = {
4+
presets: [
5+
[
6+
'@babel/preset-env', {
7+
targets: {
8+
node: true,
9+
}
10+
}
11+
]
12+
],
13+
plugins: ['macros'],
14+
};

Diff for: jest.config.js

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
// All imported modules in your tests should be mocked automatically
6+
// automock: false,
7+
8+
// Stop running tests after the first failure
9+
// bail: false,
10+
11+
// Respect "browser" field in package.json when resolving modules
12+
// browser: false,
13+
14+
// The directory where Jest should store its cached dependency information
15+
// cacheDirectory: "/var/folders/8y/bvd9gv354h5f76mmxkt_10q00000gp/T/jest_dy",
16+
17+
// Automatically clear mock calls and instances between every test
18+
clearMocks: true,
19+
20+
// Indicates whether the coverage information should be collected while executing the test
21+
// collectCoverage: false,
22+
23+
// An array of glob patterns indicating a set of files for which coverage information should be collected
24+
// collectCoverageFrom: null,
25+
26+
// The directory where Jest should output its coverage files
27+
// coverageDirectory: null,
28+
29+
// An array of regexp pattern strings used to skip coverage collection
30+
// coveragePathIgnorePatterns: [
31+
// "/node_modules/"
32+
// ],
33+
34+
// A list of reporter names that Jest uses when writing coverage reports
35+
// coverageReporters: [
36+
// "json",
37+
// "text",
38+
// "lcov",
39+
// "clover"
40+
// ],
41+
42+
// An object that configures minimum threshold enforcement for coverage results
43+
// coverageThreshold: null,
44+
45+
// Make calling deprecated APIs throw helpful error messages
46+
// errorOnDeprecated: false,
47+
48+
// Force coverage collection from ignored files usin a array of glob patterns
49+
// forceCoverageMatch: [],
50+
51+
// A path to a module which exports an async function that is triggered once before all test suites
52+
// globalSetup: null,
53+
54+
// A path to a module which exports an async function that is triggered once after all test suites
55+
// globalTeardown: null,
56+
57+
// A set of global variables that need to be available in all test environments
58+
// globals: {},
59+
60+
// An array of directory names to be searched recursively up from the requiring module's location
61+
// moduleDirectories: [
62+
// "node_modules"
63+
// ],
64+
65+
// An array of file extensions your modules use
66+
// moduleFileExtensions: [
67+
// "js",
68+
// "json",
69+
// "jsx",
70+
// "node"
71+
// ],
72+
73+
// A map from regular expressions to module names that allow to stub out resources with a single module
74+
// moduleNameMapper: {},
75+
76+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
77+
// modulePathIgnorePatterns: [],
78+
79+
// Activates notifications for test results
80+
// notify: false,
81+
82+
// An enum that specifies notification mode. Requires { notify: true }
83+
// notifyMode: "always",
84+
85+
// A preset that is used as a base for Jest's configuration
86+
// preset: null,
87+
88+
// Run tests from one or more projects
89+
// projects: null,
90+
91+
// Use this configuration option to add custom reporters to Jest
92+
// reporters: undefined,
93+
94+
// Automatically reset mock state between every test
95+
// resetMocks: false,
96+
97+
// Reset the module registry before running each individual test
98+
// resetModules: false,
99+
100+
// A path to a custom resolver
101+
// resolver: null,
102+
103+
// Automatically restore mock state between every test
104+
// restoreMocks: false,
105+
106+
// The root directory that Jest should scan for tests and modules within
107+
// rootDir: null,
108+
109+
// A list of paths to directories that Jest should use to search for files in
110+
// roots: [
111+
// "<rootDir>"
112+
// ],
113+
114+
// Allows you to use a custom runner instead of Jest's default test runner
115+
// runner: "jest-runner",
116+
117+
// The paths to modules that run some code to configure or set up the testing environment before each test
118+
// setupFiles: [],
119+
120+
// The path to a module that runs some code to configure or set up the testing framework before each test
121+
// setupTestFrameworkScriptFile: null,
122+
123+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
124+
// snapshotSerializers: [],
125+
126+
// The test environment that will be used for testing
127+
testEnvironment: "node",
128+
129+
// Options that will be passed to the testEnvironment
130+
// testEnvironmentOptions: {},
131+
132+
// Adds a location field to test results
133+
// testLocationInResults: false,
134+
135+
// The glob patterns Jest uses to detect test files
136+
// testMatch: [
137+
// "**/__tests__/**/*.js?(x)",
138+
// "**/?(*.)+(spec|test).js?(x)"
139+
// ],
140+
141+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
142+
// testPathIgnorePatterns: [
143+
// "/node_modules/"
144+
// ],
145+
146+
// The regexp pattern Jest uses to detect test files
147+
// testRegex: "",
148+
149+
// This option allows the use of a custom results processor
150+
// testResultsProcessor: null,
151+
152+
// This option allows use of a custom test runner
153+
// testRunner: "jasmine2",
154+
155+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
156+
// testURL: "http://localhost",
157+
158+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
159+
// timers: "real",
160+
161+
// A map from regular expressions to paths to transformers
162+
// transform: null,
163+
164+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
165+
// transformIgnorePatterns: [
166+
// "/node_modules/"
167+
// ],
168+
169+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
170+
// unmockedModulePathPatterns: undefined,
171+
172+
// Indicates whether each individual test should be reported during the run
173+
// verbose: null,
174+
175+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
176+
// watchPathIgnorePatterns: [],
177+
178+
// Whether to use watchman for file crawling
179+
// watchman: true,
180+
};

Diff for: package.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A Babel Macro for the require-context plugin",
55
"main": "macro/index.js",
66
"scripts": {
7-
"test": "test"
7+
"test": "jest"
88
},
99
"repository": {
1010
"type": "git",
@@ -21,6 +21,16 @@
2121
"url": "https://github.com/storybooks/require-context.macro/issues"
2222
},
2323
"homepage": "https://github.com/storybooks/require-context.macro#readme",
24+
"devDependencies": {
25+
"@babel/core": "^7.2.2",
26+
"@babel/preset-env": "^7.2.0",
27+
"babel-core": "^7.0.0-bridge.0",
28+
"babel-jest": "^23.6.0",
29+
"babel-plugin-macros": "^2.4.2",
30+
"babel-plugin-tester": "^5.5.2",
31+
"jest": "^23.6.0",
32+
"regenerator-runtime": "^0.13.1"
33+
},
2434
"peerDependencies": {
2535
"babel-plugin-macros": "^2.4.2"
2636
}

Diff for: require-context.macro.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pluginTester from 'babel-plugin-tester';
2+
import plugin from 'babel-plugin-macros';
3+
4+
describe('require-context.macro', () => {
5+
pluginTester({
6+
plugin,
7+
snapshot: true,
8+
babelOptions: { filename: __filename },
9+
tests: [
10+
`
11+
import requireContext from './macro';
12+
13+
requireContext('../src/components', true, /\.stories\.js$/);
14+
`,
15+
],
16+
});
17+
});

0 commit comments

Comments
 (0)