Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more test cases. #502

Merged
merged 1 commit into from
Dec 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
"airbnb-base/legacy"
],
"globals": {
"afterEach": true,
"beforeEach": true,
"afterAll": true,
"beforeAll": true,
"describe": true,
"expect": true,
"it": true,
"fit": true,
"expect": true,
"xit": true,
"test": true,
"xdescribe": true,
"fdescribe": true
},
"fdescribe": true,
"xit": true,
"xtest": true
},
"rules": {
"max-len": [
2,
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@
"prebuild": "npm run lint && npm run test",
"build": "node ./src/build/build.js",
"example": "node ./src/build/example.js ",
"lint": "node ./node_modules/eslint/bin/eslint src",
"lint": "eslint src tests",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "jest --config ./jest.config.json"
"test": "jest -c ./jest.config.json"
},
"devDependencies": {
"eslint": "^3.12.0",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.1",
"eslint-plugin-react": "^6.6.0",
"ncp": "^2.0.0",
"jest-cli": "^17.0.3",
"lodash": "^4.17.2",
"vscode": "^1.0.0",
"jest-cli": "^17.0.3"
"ncp": "^2.0.0",
"vscode": "^1.0.0"
},
"dependencies": {
"open": "0.0.5",
Expand Down
5 changes: 3 additions & 2 deletions src/build/iconGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function buildJsonStructure(iconsFolderBasePath) {
};

current.languages.forEach(function (langIds) {
if (_.isArray(langIds)) {
if (Array.isArray(langIds)) {
langIds.forEach(function (id) { assignLanguages(id); });
} else {
assignLanguages(langIds);
Expand Down Expand Up @@ -227,5 +227,6 @@ module.exports = {
generate: generate,
removeFirstDot: removeFirstDot,
getPathToDirName: getPathToDirName,
getDefaultSchema: getDefaultSchema
getDefaultSchema: getDefaultSchema,
buildJsonStructure: buildJsonStructure
};
2 changes: 1 addition & 1 deletion src/build/languages.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
exports.languages = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @JimiC but I still don't get the rationale here. Could you ellaborate this change?

Copy link
Member Author

@JimiC JimiC Dec 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't actually exporting a module per say, but a helper object, which falls into the category of the exports case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same as we do with supportedExtensions, supportedFolders, defaultSchema.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I still don't see the point. As far as I know this is a matter of preference and its use will depend greatly on the way we're going to compose our module. Being this just the only export, I don't see this syntactic change as if it's bringing some benefit to the table.

The examples you reference are composed like that (in the case of supportedExtensions and supportedFolders) because when I first built the extension I thought that they were going to export more items. Finally they remained like that. No other reason behind it. In fact, I've thought of refactoring these modules for a long time but I've been a little bit careless with style in this project.

The way I see it, if I know my module is going to only export one item I don't like creating extra properties. It's like a default for ES5, in this case.

You see I may have also something in my inheritance that leans me towars bizantine discussions 😜

In order to close this, let's keep it this way for the sake of consistency as I myself haven't made it clear in the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to change every exports to module.exports? I can do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no, don't worry @JimiC. I just wanted to understand why you decided to change this. I thought that maybe it was something that I was missing but now I see it's consistency or preference what was driving you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Once again I failed to express myself clearly. 😞

javascript: 'javascript',
perl: ['perl', 'perl6'],
prolog: 'prolog'
Expand Down
2 changes: 1 addition & 1 deletion src/build/supportedExtensions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-len */
var languages = require('./languages');
var languages = require('./languages').languages;
exports.extensions = {
supported: [
{ icon: 'actionscript', extensions: ['as'] },
Expand Down
150 changes: 149 additions & 1 deletion tests/iconGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('generating icons', function () {
expect(iconGenerator.getPathToDirName(toDirName, fromDirPath)).toEqual(pathTo);
});

it('ensures each supported extension has an associated icon file', function () {
it('ensures each supported file extension has an associated icon file', function () {
var suffix = '@2x';
var iconDirPath = iconGenerator.getPathToDirName('icons', '.');

Expand All @@ -44,6 +44,154 @@ describe('generating icons', function () {
});
});

it('ensures each supported folder has an associated opened icon file', function () {
var suffix = '@2x';
var iconDirPath = iconGenerator.getPathToDirName('icons', '.');

folders.supported.forEach(function (folder) {
var iconFileExtension = folder.svg ? '.svg' : '.png';
var iconOpenFilePath = iconDirPath + 'folder_type_' +
folder.icon + '_opened' + suffix + iconFileExtension;

expect(fs.existsSync(iconOpenFilePath)).toBeTruthy();
});
});

it('ensures each supported file extension has a definition', function () {
var fileDefinitions = iconGenerator.buildJsonStructure().files.defs;

files.supported.forEach(function (file) {
var definition = '_f_' + file.icon;
expect(fileDefinitions[definition]).toBeDefined();
});
});

it('ensures each supported file extension has an icon path', function () {
var fileDefinitions = iconGenerator.buildJsonStructure().files.defs;

files.supported.forEach(function (file) {
var definition = '_f_' + file.icon;
expect(fileDefinitions[definition].iconPath).toBeDefined();
});
});

it('ensures each supported folder has a definition', function () {
var folderDefinitions = iconGenerator.buildJsonStructure().folders.defs;

folders.supported.forEach(function (folder) {
var definition = '_fd_' + folder.icon;
expect(folderDefinitions[definition]).toBeDefined();
});
});

it('ensures each supported folder has an open definition', function () {
var folderDefinitions = iconGenerator.buildJsonStructure().folders.defs;

folders.supported.forEach(function (folder) {
var definition = '_fd_' + folder.icon + '_open';
expect(folderDefinitions[definition]).toBeDefined();
});
});

it('ensures each supported folder has an icon path', function () {
var folderDefinitions = iconGenerator.buildJsonStructure().folders.defs;

folders.supported.forEach(function (folder) {
var definition = '_fd_' + folder.icon;
expect(folderDefinitions[definition].iconPath).toBeDefined();
});
});

it('ensures each supported folder has an open icon path', function () {
var folderDefinitions = iconGenerator.buildJsonStructure().folders.defs;

folders.supported.forEach(function (folder) {
var definition = '_fd_' + folder.icon + '_open';
expect(folderDefinitions[definition].iconPath).toBeDefined();
});
});

it('ensures each supported folder has a folder name referencing its definiton',
function () {
var folderNames = iconGenerator.buildJsonStructure().folders.names.folderNames;

folders.supported.forEach(function (folder) {
var definition = '_fd_' + folder.icon;
folder.extensions.forEach(function (extension) {
var extensionName = (folder.dot ? '.' : '') + extension;
expect(folderNames[extensionName]).toEqual(definition);
});
});
});

it('ensures each supported folder has a folder name expanded referencing its definiton',
function () {
var folderNamesExpanded = iconGenerator.buildJsonStructure()
.folders.names.folderNamesExpanded;

folders.supported.forEach(function (folder) {
var definition = '_fd_' + folder.icon + '_open';
folder.extensions.forEach(function (extension) {
var extensionName = (folder.dot ? '.' : '') + extension;
expect(folderNamesExpanded[extensionName]).toEqual(definition);
});
});
});

it('ensures each supported file extension that is not a filename ' +
'has a file extension referencing its definiton',
function () {
var fileExtensions = iconGenerator.buildJsonStructure().files.names.fileExtensions;

files.supported
.filter(function (file) { return !file.filename && !file.languages; })
.forEach(function (file) {
var definition = '_f_' + file.icon;
file.extensions.forEach(function (extension) {
var extensionName = iconGenerator.removeFirstDot(extension);
expect(fileExtensions[extensionName]).toEqual(definition);
});
});
});

it('ensures each supported file extension that is a filename ' +
'has a file name referencing its definiton',
function () {
var fileNames = iconGenerator.buildJsonStructure().files.names.fileNames;

files.supported
.filter(function (file) { return file.filename && !file.languages; })
.forEach(function (file) {
var definition = '_f_' + file.icon;
file.extensions.forEach(function (extension) {
expect(fileNames[extension]).toEqual(definition);
});
});
});

it('ensures each supported file extension that is supported by language ids ' +
'has a language id referencing its definiton',
function () {
var languageIds = iconGenerator.buildJsonStructure().files.names.languageIds;

files.supported
.filter(function (file) { return file.languages; })
.forEach(function (file) {
var definition = '_f_' + file.icon;
var assertLanguage = function (language) {
expect(languageIds[language]).toEqual(definition);
};

file.languages.forEach(function (langIds) {
if (Array.isArray(langIds)) {
langIds.forEach(function (id) { assertLanguage(id); });
} else {
assertLanguage(langIds);
}
});
});
});

/*
This can be unskipped once 'toMatchObject' method has been released by facebook.
See: https://github.com/facebook/jest/issues/2195
Expand Down