Skip to content

Commit

Permalink
#45 update file structure, update tests, update webpack config
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-serb committed Jul 15, 2023
1 parent 517ed53 commit 4d707a5
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 34 deletions.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/entries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
index: './pages/index/index.js',
};
File renamed without changes.
8 changes: 4 additions & 4 deletions src/game-of-life.js → src/game/game-of-life.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

import Gameloop from '@/gameloop.js';
import Map from '@/map.js';
import Figures from '@/figures.js';
import { getRandomInteger } from '@/helpers.js';
import Gameloop from '@/engine/gameloop.js';
import Map from '@/game/map.js';
import Figures from '@/game/figures.js';
import { getRandomInteger } from '@/engine/helpers.js';

export class GameOfLife extends Gameloop {
constructor() {
Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

import GameOfLife from '@/game-of-life.js';
const ENTRIES = require('./entries.js');
const PAGES = require('./pages.js');

new GameOfLife();
module.exports = {
ENTRIES,
PAGES,
};
12 changes: 12 additions & 0 deletions src/pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const HTMLWebpackPlugin = require('html-webpack-plugin');

module.exports = [
new HTMLWebpackPlugin({
inject: true,
template: './pages/index/index.html',
filename: 'index.html',
chunks: ['index'],
}),
];
File renamed without changes.
5 changes: 5 additions & 0 deletions src/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

import GameOfLife from '@/game/game-of-life.js';

new GameOfLife();
2 changes: 1 addition & 1 deletion tests/gameloop.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import Gameloop from '@/gameloop.js';
import Gameloop from '@/engine/gameloop.js';

describe('[Class][Gameloop] create instance', () => {
const gameloop = new Gameloop();
Expand Down
29 changes: 12 additions & 17 deletions tests/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
'use strict';

import { getRandomInteger } from '@/helpers.js';
import { getRandomInteger } from '@/engine/helpers.js';

describe('[Helpers] function getRandomInteger', () => {
test('Call without params', () => {
expect(getRandomInteger()).toBe(0);
const number = getRandomInteger();

expect(number).toBe(0);
expect(typeof number).toBe('number');
});

test('Generate number and only number', () => {
test('Generate many time number with params', () => {
const min = 0;
const max = 10;
const count = 100;
const arr = [];
let isValid = true;

for (let i = 0; i < count; i++) {
arr.push(getRandomInteger(min, max));
}

const isntValid = false;
const number = getRandomInteger(min, max);

for (let i = 0; i < arr.length; i++) {
if (!typeof arr[i] === 'number') {
isntValid = true;
} else {
if (Math.trunc(arr[i]) !== arr[i]) {
isntValid = true;
}
if (!typeof number === 'number' ||
number < min || number >= max) {
isValid = false;
}
if (isntValid) break;
}

expect(arr.includes(true)).not.toBe(true);
expect(isValid).toBe(true);
});
});
17 changes: 7 additions & 10 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ const path = require('path');
const ESLintWebpackPlugin = require('eslint-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const babelConfig = require('./babel.config');
const { ENTRIES, PAGES } = require('./src');

module.exports = (env, argv) => {
return {
mode: argv.mode || 'development',
context: path.resolve(__dirname, 'src'),
entry: {
index: './index.js',
},
entry: ENTRIES,
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'docs'),
Expand Down Expand Up @@ -51,12 +49,7 @@ module.exports = (env, argv) => {
},
],
}),
new HTMLWebpackPlugin({
inject: true,
template: './index.html',
filename: 'index.html',
chunks: ['index'],
}),
...PAGES,
],
module: {
rules: [
Expand All @@ -68,6 +61,10 @@ module.exports = (env, argv) => {
options: babelConfig,
},
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
};
Expand Down

0 comments on commit 4d707a5

Please sign in to comment.