Skip to content

Commit

Permalink
feat: (strf-8608) replaced lab+code+sinon with jest
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGenash committed Sep 9, 2020
1 parent 5f89a04 commit 71e952f
Show file tree
Hide file tree
Showing 42 changed files with 1,387 additions and 2,389 deletions.
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
"impliedStrict": true
}
},
"plugins": ["jest"],
"extends": [
"plugin:jest/recommended",
"plugin:jest/style"
],
"env": {
"es2020": true,
"jest/globals": true,
"node": true
},
"rules": {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ jspm_packages
node_modules
npm-debug.log
.DS_Store
.coverage/
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ cache:
install:
- npm install
script:
- npm test
- npm run lint
- npm run test-with-coverage
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ install:
test_script:
- node --version
- npm --version
- npm test
- npm run lint
- npm run test-with-coverage
build: off
11 changes: 7 additions & 4 deletions bin/stencil-bundle → bin/stencil-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ Program
.parse(process.argv);

if (!versionCheck()) {
return;
process.exit(2);
}

themeConfig = ThemeConfig.getInstance(themePath);

if (Program.dest === true) {
return console.error('Error: You have to specify a value for -d or --dest'.red);
console.error('Error: You have to specify a value for -d or --dest'.red);
process.exit(2);
}

if (Program.name === true) {
return console.error('Error: You have to specify a value for -n or --name'.red);
console.error('Error: You have to specify a value for -n or --name'.red);
process.exit(2);
}

if (!themeConfig.configExists()) {
return console.error('Error: You must have a '.red + 'config.json'.cyan + ' file in your top level theme directory.');
console.error('Error: You must have a '.red + 'config.json'.cyan + ' file in your top level theme directory.');
process.exit(2);
}

configuration = themeConfig.getRawConfig();
Expand Down
2 changes: 1 addition & 1 deletion bin/stencil-init → bin/stencil-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Program
.parse(process.argv);

if (!versionCheck()) {
return;
process.exit(2);
}

const dotStencilFilePath = './.stencil';
Expand Down
2 changes: 1 addition & 1 deletion bin/stencil-pull → bin/stencil-pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Program
.parse(process.argv);

if (!versionCheck()) {
return;
process.exit(2);
}

stencilPull(Object.assign({}, options, {
Expand Down
4 changes: 2 additions & 2 deletions bin/stencil-push → bin/stencil-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Program
.parse(process.argv);

if (!versionCheck()) {
return;
process.exit(2);
}

stencilPush(Object.assign({}, options, {
Expand All @@ -32,7 +32,7 @@ stencilPush(Object.assign({}, options, {
}), (err, result) => {
if (err) {
console.log("\n\n" + 'not ok'.red + ` -- ${err} see details below:`);
themeApiClient.printErrorMessages(err.messages)
themeApiClient.printErrorMessages(err.messages);
console.log('If this error persists, please visit https://github.com/bigcommerce/stencil-cli/issues and submit an issue.');
} else {
console.log('ok'.green + ` -- ${result}`);
Expand Down
2 changes: 1 addition & 1 deletion bin/stencil-release → bin/stencil-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Program
.parse(process.argv);

if (!versionCheck()) {
return;
process.exit(2);
}

release();
70 changes: 31 additions & 39 deletions bin/stencil-start → bin/stencil-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Pkg = require('../package.json');
const Program = require('commander');
const Server = require('../server');
const ThemeConfig = require('../lib/theme-config');
const buildConfig = require('../lib/build-config');
const BuildConfigManager = require('../lib/BuildConfigManager');
const jsonLint = require('../lib/json-lint');
const versionCheck = require('../lib/version-check');

Expand All @@ -36,23 +36,26 @@ Program
// https://browsersync.io/docs/options#option-tunnel
const tunnel = typeof Program.tunnel === 'string'
? Program.tunnel
: Boolean(Program.tunnel) // convert undefined/true -> false/true
: Boolean(Program.tunnel); // convert undefined/true -> false/true

if (!versionCheck()) {
return;
process.exit(2);
}

if (!fileExist(dotStencilFilePath)) {
return console.error('Error: Please run'.red + ' $ stencil init'.cyan + ' first.'.red);
console.error('Error: Please run'.red + ' $ stencil init'.cyan + ' first.'.red);
process.exit(2);
}

if (!fileExist(Path.join(themePath, 'config.json'))) {
return console.error('Error: You must have a '.red + 'config.json'.cyan + ' file in your top level theme directory.');
console.error('Error: You must have a '.red + 'config.json'.cyan + ' file in your top level theme directory.');
process.exit(2);
}

// If the value is true it means that no variation was passed in.
if (Program.variation === true) {
return console.error('Error: You have to specify a value for -v or --variation'.red);
console.error('Error: You have to specify a value for -v or --variation'.red);
process.exit(2);
}

// Instantiate themeConfig
Expand All @@ -61,25 +64,27 @@ if (Program.variation) {
try {
themeConfig.setVariationByName(Program.variation);
} catch (err) {
return console.error('Error: The variation '.red + Program.variation + ' does not exists in your config.json file'.red);
console.error('Error: The variation '.red + Program.variation + ' does not exists in your config.json file'.red);
process.exit(2);
}
}

let configuration = themeConfig.getConfig();
let dotStencilFile = Fs.readFileSync(dotStencilFilePath, {encoding: 'utf-8'});
let dotStencilFile = Fs.readFileSync(dotStencilFilePath, { encoding: 'utf-8' });
try {
dotStencilFile = jsonLint.parse(dotStencilFile, dotStencilFilePath);
} catch (e) {
return console.error(e.stack);
console.error(e.stack);
process.exit(2);
}

let browserSyncPort = dotStencilFile.port;
let stencilServerPort = ++dotStencilFile.port;
if (!(dotStencilFile.normalStoreUrl) || !(dotStencilFile.customLayouts)) {
return console.error(
console.error(
'Error: Your stencil config is outdated. Please run'.red +
' $ stencil init'.cyan + ' again.'.red
' $ stencil init'.cyan + ' again.'.red,
);
process.exit(2);
}

let staplerUrl;
Expand All @@ -101,18 +106,16 @@ Wreck.get(
rejectUnauthorized: false,
},
function (err, res, payload) {
let bundleTask;

if (err || !payload) {
console.error(
'The BigCommerce Store you are pointing to either does not exist or is not available at this time.'.red
'The BigCommerce Store you are pointing to either does not exist or is not available at this time.'.red,
);
} else if (payload.error) {
return console.error(payload.error.red);
} else if (payload.status !== 'ok') {
console.error(
'Error: You are using an outdated version of stencil-cli, please run '.red +
'$ npm install -g @bigcommerce/stencil-cli'.cyan
'$ npm install -g @bigcommerce/stencil-cli'.cyan,
);
} else {
dotStencilFile.storeUrl = payload.sslUrl;
Expand All @@ -121,7 +124,7 @@ Wreck.get(

return startServer();
}
}
},
);

/**
Expand All @@ -135,11 +138,12 @@ async function startServer() {
themePath: themePath,
});

const buildConfigManger = new BuildConfigManager();
let watchFiles = [
'/assets',
'/templates',
'/lang',
'/.config'
'/.config',
];
let watchIgnored = [
'/assets/scss',
Expand All @@ -156,25 +160,13 @@ async function startServer() {
}
});

Bs.watch('config.json', (event) => {
if (event === 'change') {
try {
configuration = themeConfig.getConfig();
} catch (e) {
return console.error(e);
}

Bs.reload();
}
});

Bs.watch('.config/storefront.json', (event, file) => {
if (event === 'change') {
console.log("storefront json changed");
Bs.emitter.emit("storefront_config_file:changed", {
event: event,
path: file,
namespace: ""
namespace: "",
});
Bs.reload();
}
Expand All @@ -191,15 +183,15 @@ async function startServer() {
} catch (e) {
console.error(e);
}
})
});
});

if (buildConfig.watchOptions && buildConfig.watchOptions.files) {
watchFiles = buildConfig.watchOptions.files;
if (buildConfigManger.watchOptions && buildConfigManger.watchOptions.files) {
watchFiles = buildConfigManger.watchOptions.files;
}

if (buildConfig.watchOptions && buildConfig.watchOptions.ignored) {
watchIgnored = buildConfig.watchOptions.ignored;
if (buildConfigManger.watchOptions && buildConfigManger.watchOptions.ignored) {
watchIgnored = buildConfigManger.watchOptions.ignored;
}

Bs.init({
Expand Down Expand Up @@ -227,8 +219,8 @@ async function startServer() {
}
});

if (buildConfig.development) {
buildConfig.initWorker().development(Bs);
if (buildConfigManger.development) {
buildConfigManger.initWorker().development(Bs);
}
}

Expand All @@ -248,7 +240,7 @@ function assembleTemplates(templatePath, callback) {
callback(err);
}
callback(null, results);
})
});
});
}

Expand Down
File renamed without changes.
31 changes: 31 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
collectCoverage: false,
collectCoverageFrom: [
'./bin/**/*.js',
'./server/**/*.js',
'./lib/**/*.js',
'./tasks/**/*.js',
],
coverageDirectory: './.coverage',
coverageThreshold: {
global: {
branches: 33,
functions: 47,
lines: 47,
statements: 47,
},
},
moduleFileExtensions: [
"js",
"json",
"node",
],
testEnvironment: "node",
testMatch: [
"**/__tests__/**/*.[jt]s",
"**/?(*.)+(spec|test).[tj]s",
],
};
Loading

0 comments on commit 71e952f

Please sign in to comment.