Skip to content

Commit 85270e3

Browse files
authored
Merge pull request #85 from ampersarnie/hotfix/formatting
Code formatting and tests
2 parents b4b3e7f + 06a69d6 commit 85270e3

30 files changed

+12685
-2192
lines changed

.eslintrc

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
{
2-
"extends": ["airbnb-base"],
3-
"plugins": ["cypress"],
2+
"extends": ["airbnb-base", "prettier"],
3+
"plugins": ["cypress", "prettier", "jest"],
44
"ignorePatterns": ["lib/cypress-plugin/tmp/*"],
55
"env": {
66
"browser": true,
77
"node": true,
8-
"cypress/globals": true
8+
"cypress/globals": true,
9+
"jest/globals": true
10+
},
11+
"parserOptions": {
12+
"parser": "@babel/eslint-parser",
13+
"requireConfigFile": false
914
},
10-
"parser": "@babel/eslint-parser",
1115
"rules": {
12-
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }]
16+
"prettier/prettier": "error",
17+
"import/no-extraneous-dependencies": [
18+
"error",
19+
{
20+
"devDependencies": true
21+
}
22+
],
23+
"arrow-parens": 2
1324
}
1425
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ debug.log
4141
config.json
4242
tmp
4343
wp-content
44+
coverage

.husky/pre-push

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
npm test
2+
npm run lint:scripts

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 100,
3+
"trailingComma": "all",
4+
"arrowParens": "always",
5+
"singleQuote": true
6+
}

jest.config.js

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

lib/cli/commands/reset.js

+27-16
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ const getWPInstallType = require('../../modules/getWPInstallType');
1717
const reset = async (packageDir, logFile, options) => {
1818
const config = fs.readJsonSync(`${packageDir}/config.json`);
1919

20-
const version = (options && isString(options.version))
21-
? options.version
22-
: config.validVersions[0];
20+
const version = options && isString(options.version) ? options.version : config.validVersions[0];
2321

2422
shell.cd(packageDir);
2523

@@ -32,13 +30,17 @@ const reset = async (packageDir, logFile, options) => {
3230
const locale = get(config, ['locale'], 'en_US');
3331

3432
await run(
35-
async () => wpcli(
36-
`core config --dbhost=db --dbname=wordpress --dbuser=root --dbpass="" --locale=${locale} --extra-php`,
37-
logFile,
38-
`define( 'FS_METHOD', 'direct' );
39-
40-
${map(config.config, (value, key) => `
41-
define( '${key}', ${isString(value) ? `'${value}'` : value} );`).join('')}
33+
async () =>
34+
wpcli(
35+
`core config --dbhost=db --dbname=wordpress --dbuser=root --dbpass="" --locale=${locale} --extra-php`,
36+
logFile,
37+
`define( 'FS_METHOD', 'direct' );
38+
39+
${map(
40+
config.config,
41+
(value, key) => `
42+
define( '${key}', ${isString(value) ? `'${value}'` : value} );`,
43+
).join('')}
4244
4345
if ( file_exists( __DIR__ . '/wp-cypress-config.php' ) ) {
4446
require_once __DIR__ . '/wp-cypress-config.php';
@@ -50,7 +52,7 @@ if( file_exists ( ABSPATH . '.userid' ) ) {
5052
}
5153
}
5254
`,
53-
),
55+
),
5456
'Creating wp-config.php',
5557
'wp-config.php created',
5658
logFile,
@@ -64,10 +66,13 @@ if( file_exists ( ABSPATH . '.userid' ) ) {
6466
);
6567

6668
await run(
67-
async () => wpcli(
68-
`core ${getWPInstallType(config.multisite)} --url=${config.url} --title="WP Cypress" --admin_user=admin --admin_password=password --admin_email="admin@test.com" --skip-email`,
69-
logFile,
70-
),
69+
async () =>
70+
wpcli(
71+
`core ${getWPInstallType(config.multisite)} --url=${
72+
config.url
73+
} --title="WP Cypress" --admin_user=admin --admin_password=password --admin_email="admin@test.com" --skip-email`,
74+
logFile,
75+
),
7176
'Installing WordPress',
7277
'WordPress installed',
7378
logFile,
@@ -83,7 +88,13 @@ if( file_exists ( ABSPATH . '.userid' ) ) {
8388
}
8489

8590
await run(
86-
async () => wpcli(`plugin activate wp-cypress ${config.activePlugins.join(' ')} ${config.multisite ? '--network' : ''}`, logFile),
91+
async () =>
92+
wpcli(
93+
`plugin activate wp-cypress ${config.activePlugins.join(' ')} ${
94+
config.multisite ? '--network' : ''
95+
}`,
96+
logFile,
97+
),
8798
'Activating plugins',
8899
'Activated plugins',
89100
logFile,

lib/cli/commands/softReset.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const run = require('../../modules/run');
1515
const softReset = async (packageDir, logFile, options = false) => {
1616
const config = fs.readJsonSync(`${packageDir}/config.json`);
1717

18-
const version = (options && isString(options.version))
19-
? options.version
20-
: config.validVersions[0];
18+
const version = options && isString(options.version) ? options.version : config.validVersions[0];
2119

2220
shell.cd(packageDir);
2321

lib/cli/commands/start.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ const start = async (packageDir, options, logFile) => {
2828
shell.cd(packageDir);
2929

3030
await run(
31-
async () => exec(
32-
'docker-compose down --volumes && docker-compose build && docker-compose up -d',
33-
logFile,
34-
),
31+
async () =>
32+
exec(
33+
'docker-compose down --volumes && docker-compose build && docker-compose up -d',
34+
logFile,
35+
),
3536
'Creating test container',
3637
'Test container created',
3738
logFile,
@@ -45,10 +46,7 @@ const start = async (packageDir, options, logFile) => {
4546
);
4647

4748
await run(
48-
async () => cli(
49-
'composer install -d /var/www/html/wp-content/plugins/wp-cypress',
50-
logFile,
51-
),
49+
async () => cli('composer install -d /var/www/html/wp-content/plugins/wp-cypress', logFile),
5250
'Installing wp-cypress dependencies',
5351
'Dependencies installed',
5452
logFile,

lib/cli/commands/wp.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ const run = require('../../modules/run');
1212
const wp = async (command, packageDir, logFile) => {
1313
shell.cd(packageDir);
1414

15-
await run(
16-
async () => wpcli(command, logFile),
17-
`Running wp ${command}`,
18-
);
15+
await run(async () => wpcli(command, logFile), `Running wp ${command}`);
1916
};
2017

2118
module.exports = wp;

lib/cli/index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ program
2929

3030
program
3131
.command('reset')
32-
.description('Hard reset the installation to it\'s initial state')
32+
.description("Hard reset the installation to it's initial state")
3333
.option('-v,--version <version>')
3434
.action((options) => reset(packageDir, logFile, options));
3535

3636
program
3737
.command('soft-reset')
38-
.description('Soft reset the installation to it\'s initial state')
38+
.description("Soft reset the installation to it's initial state")
3939
.option('-v,--version <version>')
4040
.action((options) => softReset(packageDir, logFile, options));
4141

@@ -48,10 +48,7 @@ program
4848
.command('seed')
4949
.description('Execute WordPress CLI seed command.')
5050
.option('<seeder>', 'The name of the seeder to run.')
51-
.option(
52-
'-cf, --clean-first',
53-
'Whether to run the clean routine before seeding.',
54-
)
51+
.option('-cf, --clean-first', 'Whether to run the clean routine before seeding.')
5552
.option('-c, --clean', 'Run only the seeder clean routine.')
5653
.action((options) => {
5754
let cleanFlag = '';

0 commit comments

Comments
 (0)