-
Notifications
You must be signed in to change notification settings - Fork 11
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
CPD-1653: Added f-logger changes to GBF, Updated unit tests to cover … #116
Conversation
test/config.test.js
Outdated
expect(config.logger).toBeDefined(); | ||
}); | ||
|
||
describe('`dir` it should exist', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing a different structure into the tests here — I know we discussed this before and agreed that we should hold a discussion on how best to structure tests but can we hold off on changing parts of the test files for now? It's a bit confusing when scanning through the file.
If/when we decide to change this structure I think it should all be done in a single PR, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I will update it. I think we should refactor whatever we touch if/when we decide we want to change the structure, instead of doing massive changes in one PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There aren't that many tests so it might be OK to do the whole lot, depends how much we want to change the structure I guess.
@@ -270,6 +270,37 @@ describe('javascript config', () => { | |||
|
|||
}); | |||
|
|||
|
|||
describe('`logger` config', () => { | |||
it('should exist', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no tests to check that the values can be updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
test/config.test.js
Outdated
}); | ||
|
||
describe('`dir` it should exist', () => { | ||
expect(config.logger.dir).toBeDefined(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't the following test already cover the defined scenario? i.e. it'll fail if it doesn't match 'JavaScript'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is different to the test below. The idea here is that it will fail should the object property dir
not exist. The second one is more of a value check, but I know what you mean, the value wouldn't pass if the dir
isn't there in the first place so having it fail before that check makes it easier to spot what the actual fix is, what do you think?
tasks/logger-file.js
Outdated
*/ | ||
|
||
gulp.task('logger-file-create', () => { | ||
const fullFilePath = `${pathBuilder.jsErrorLoggerSubDir}/${config.logger.file}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use the gulp-file
module combined with gulp.dest
in order to keep the code running inside the pipe stream.
const file = require('gulp-file');
gulp.task('test', () => file(config.logger.file, '', { src: true })
.pipe(gulp.dest(pathBuilder.jsErrorLoggerDir))
);
This way there is no need to do the synchronous directory operations (gulp.dest
handles that already). It also means you don't need as many config options, unless it required that you need that level of granularity?
config.js
Outdated
* f-logger-related variables | ||
*/ | ||
logger: { | ||
dir: 'JavaScript', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What path does the js-error.js
live at? Is it at somethign like /JavaScript/Shared/js-error.js
?
Only wondering as that looks like a different directory to the rest of the JS on the site?
Can it not live in the same JS directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caught up with Simon on this and there are a few areas that require this path to be set like this (below), I think we should raise a ticket to correct these paths and then we could update this so it lives in the JS
folder, what do you think?
Ha-proxy
NXlog
Publicweb
CW
Kibana
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Publicweb and hit the global logging file then? Or is it just some sort of side-affect…
Would be good to update anywhere that needs it too though – having JS in two places just adds confusion for people new to the project as the file will just get lost otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have removed this. I'll update the jira so we can update the paths for all the other utilities that used the old path.
tasks/logger-file.js
Outdated
* | ||
*/ | ||
|
||
gulp.task('logger-file-create', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've used a slightly different naming convention for a lot of the other tasks. Might make more sense if this was called logger:createFile
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup will update.
More of question here but is it worth adding pre-commit hooks which will run unit tests and linting / anything else before we commit and push things, just to avoid pushing things that won't pass on travis? |
@kevinrodrigues Yeh, that'd be a good idea. Could save a bit of time when dev-ing he work. The other thing that I find useful is to hook up your editor to the eslint config – that way you get the warnings as you dev too |
@ashleynolan Yeah I have it hooked up but the error only highlighted after I committed and pushed (joys of WebStorm) 🐌 |
tasks/logger-file.js
Outdated
*/ | ||
|
||
gulp.task('logger:createFile', () => file(config.logger.file, '', { src: true }) | ||
.pipe(gulpif(!fs.existsSync(`${pathBuilder.jsErrorLoggerSubDir}/${config.logger.file}`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what scenario would the file already exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the gulp task runs for the first time then the file would be created, the second time round the file won't be created. The reason the check is there is to prevent gulp from erroring in the scenario where the file might already exist e.g if the task has already run once already inside a project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the sync
bit which concerns me really, feels like we're wedging synchronous code into asynchronous streams. It's probably fine in this instance as it's such a small task 🎲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have done some reading and this is the recommended way accorsing to SO, so I am happy 😸
@@ -14,6 +14,9 @@ const buildPaths = config => { | |||
jsSrcDir: `${config.assetSrcDir}/${config.js.jsDir}`, | |||
jsDistDir: `${config.assetDistDir}/${config.js.jsDir}`, | |||
|
|||
jsErrorLoggerDir: `${config.webRootDir}/${config.logger.dir}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this path anymore?
test/config.test.js
Outdated
const subDir = 'A sub directory'; | ||
const file = 'A file'; | ||
|
||
beforeEach(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally find this style harder to follow than the existing tests. When everything is declared within a single file you don't have to go scanning back up to see if there is a beforeEach
block. It doesn't add much value that I can see?
At least before the tests act more like documentation; someone can find the property they are interested in and see exactly how the properties are updated at a glance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, are we not waiting until we agree on a better to start rewriting the tests? Seems like we're introducing inconsistency because we disagree on the style. Wouldn't it be better to get on the same page before updating the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @DamianMullins I totally agree about not rewriting the tests until we agree on a structure which is why I have reverted them, but the reason I've added the beforeEach
is because my tests fail on the .toBeDefined
scenario if the config.update
isn't updated before the second and the remaining IT
block statements. I have removed the nested describes as we agreed but without repeating and updating the config multiple times for each IT
and to keep things DRY
I used beforeEach
so as to not repeat code multiple times to make it more readable & maintainable. If you would prefer me to add them to each IT
instead happy to do so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so it sounds like you have another issue in the tests, I'll have a quick look this afternoon so I fully understand the issue.
As for the comments about DRY, I'm always on the fence with applying the principle in unit tests as it tends to lead towards code which harder to reason about. Let's arrange something soon so we can discuss and put some examples together?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simonsandersje Sounds like we need that doodle to sort out the next UI Guild 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinrodrigues the issue you're having with the config value on the second run is because you need to add a line to the update()
function which allows the property to update correctly.
logger: Object.assign(config.logger, options.logger)
And then the tests can be written in the same way:
describe('`logger` config', () => {
it('should exist', () => {
expect(config.logger).toBeDefined();
});
it('`dir` should be set', () => {
expect(config.logger.dir).toBe('js/shared');
});
it('`dir` can be updated', () => {
// Arrange
const dir = 'logger/dir';
// Act
config.update({ logger: { dir } });
// Assert
expect(config.logger.dir).toBe(dir);
});
it('`file` should be set', () => {
expect(config.logger.file).toBe('js-error.js');
});
it('`file` can be updated', () => {
// Arrange
const file = 'logger.js';
// Act
config.update({ logger: { file } });
// Assert
expect(config.logger.file).toBe(file);
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are you updating the value in the code above? In the example I posted, the tests explicitly update the original value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not keep it the same as everything else in the test file? I don't understand the need to make it different at the moment?
Sorry that I'm going on about this! 🐙
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
config.js
Outdated
*/ | ||
logger: { | ||
dir: 'js', | ||
subDir: 'Shared', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lower case "shared"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
config.js
Outdated
* f-logger-related variables | ||
*/ | ||
logger: { | ||
dir: 'js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just have dir
? I don't think subDir
is needed anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PathBuilder.js requires it. Do you mean remove it and just place the logger file inside the js folder?
jsErrorLoggerSubDir: `${config.webRootDir}/${config.logger.dir}/${config.logger.subDir}`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just change config.logger.dir
to "js/shared"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool updated now.
test/config.test.js
Outdated
// `logger.file` | ||
it('`file` should exist', () => { | ||
// Assert | ||
expect(config.logger.subDir).toBeDefined(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be config.logger.file
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot.
@@ -307,6 +314,11 @@ Here is the outline of the configuration options, descriptions of each are below | |||
usePackageVersion, | |||
stripDebug | |||
}, | |||
logger: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add a description of these new properties to the docs below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the constant pestering from me 🎆
@DamianMullins Never apologise for that – just means @kevinrodrigues has to do the same on your PRs 😉 |
No description provided.