Skip to content

Commit

Permalink
Fixing tests for reset moduleId
Browse files Browse the repository at this point in the history
  • Loading branch information
JayaKrishnaNamburu committed Jul 17, 2021
1 parent 5c2afd9 commit 5c8657a
Show file tree
Hide file tree
Showing 12 changed files with 777 additions and 1,212 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = {
{
files: ['docs/*.md', 'docs/**/*.md'],
rules: {
'no-console': 'off'
'no-console': 'off',
'import/extensions': 'off'
}
},
{
Expand Down
25 changes: 20 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const webpack = require('./webpack.config')
const browsers = require('./browsers')
const webpackConfig = require('./webpack.config')
const browsers = require('./browsers.json')

const isBench = process.env.BENCHMARK === 'true'
const useCloud = process.env.USE_CLOUD === 'true'
Expand All @@ -10,24 +10,39 @@ const travisBuildNumber = process.env.TRAVIS_BUILD_NUMBER
const travisBuildId = process.env.TRAVIS_BUILD_ID
const travisJobNumber = process.env.TRAVIS_JOB_NUMBER

const getWepackConfig = () => {
delete webpackConfig.entry
delete webpackConfig.output
return webpackConfig
}

module.exports = config => {
config.set({
customLaunchers: browsers,
browsers: ['Chrome'],
frameworks: ['mocha'],
frameworks: ['mocha', 'webpack'],
files: [
'./polyfills.js',
'./packages/*/tests/*.js',
'./packages/*/tests/**/*.js',
'./packages/*/src/**/*.test.js'
],
plugins: [
'karma-webpack',
'karma-mocha',
'karma-sourcemap-loader',
'karma-mocha-reporter',
'karma-coverage',
'karma-chrome-launcher'
],
preprocessors: {
'./polyfills.js': ['webpack', 'sourcemap'],
'./packages/**/*.js': ['webpack', 'sourcemap']
},
webpack,
webpack: getWepackConfig(),
webpackMiddleware: {
stats: 'errors-only'
stats: 'errors-only',
noInfo: true
},
reporters: ['mocha', 'coverage'],
coverageReporter: {
Expand Down
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@
"yarn": ">=1.13"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.3.0",
"@babel/plugin-proposal-object-rest-spread": "^7.3.2",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/core": "^7.14.6",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
"@babel/plugin-transform-runtime": "^7.14.5",
"@babel/preset-env": "^7.14.7",
"@babel/preset-flow": "^7.14.5",
"@babel/preset-react": "^7.14.5",
"@lerna/prompt": "^3.6.0",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@rollup/plugin-replace": "^2.3.4",
"@types/node": "^14.0.9",
"axios": "^0.18.0",
"babel-loader": "^8.0.4",
"babel-plugin-dev-expression": "^0.2.1",
"babel-loader": "^8.2.2",
"babel-plugin-dev-expression": "^0.2.2",
"camelcase": "^5.0.0",
"chalk": "^2.4.1",
"codecov": "^3.6.5",
Expand All @@ -74,19 +74,19 @@
"expect.js": "^0.3.1",
"flow-bin": "^0.138.0",
"json-loader": "^0.5.4",
"karma": "^1.3.0",
"karma-benchmark": "^0.6.0",
"karma": "^6.3.4",
"karma-benchmark": "^1.0.4",
"karma-benchmark-reporter": "^0.1.1",
"karma-browserstack-launcher": "^1.4.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-browserstack-launcher": "^1.6.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.3",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.8",
"karma-webpack": "^5.0.0",
"lerna": "^3.8.0",
"lint-staged": "^3.2.2",
"mocha": "^3.2.0",
"mocha": "^9.0.2",
"npmlog": "^4.1.2",
"pre-commit": "^1.1.3",
"prettier": "^1.13.5",
Expand All @@ -100,7 +100,7 @@
"shelljs": "^0.8.2",
"sinon": "4.5.0",
"typescript": "^3.7.0",
"webpack": "^5.42.0",
"webpack": "^5.45.1",
"zen-observable": "^0.6.0"
}
}
26 changes: 13 additions & 13 deletions packages/jss/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"jss.js": {
"bundled": 63771,
"minified": 23307,
"gzipped": 7132
"bundled": 63661,
"minified": 23308,
"gzipped": 7131
},
"jss.min.js": {
"bundled": 62384,
"bundled": 62274,
"minified": 22543,
"gzipped": 6769
"gzipped": 6771
},
"jss.cjs.js": {
"bundled": 59498,
"minified": 26181,
"gzipped": 7202
"bundled": 59388,
"minified": 26209,
"gzipped": 7211
},
"jss.esm.mjs": {
"bundled": 57910,
"minified": 24909,
"gzipped": 7030,
"bundled": 57800,
"minified": 24937,
"gzipped": 7040,
"treeshaked": {
"rollup": {
"code": 20343,
"code": 20345,
"import_statements": 345
},
"webpack": {
"code": 21826
"code": 21827
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jss/src/RuleList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import createRule from './utils/createRule'
import {StyleRule, KeyframesRule} from './plugins/index'
import {StyleRule, KeyframesRule} from './plugins'
import type {
RuleListOptions,
ToCssOptions,
Expand Down
4 changes: 2 additions & 2 deletions packages/jss/src/plugins/keyframesRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type {
JssStyle,
RuleOptions,
ToCssOptions,
ContainerRule,
KeyframesMap,
Plugin
Plugin,
ContainerRule
} from '../types'
import escape from '../utils/escape'

Expand Down
3 changes: 2 additions & 1 deletion packages/jss/src/utils/createGenerateId.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import warning from 'tiny-warning'
import type {Rule} from '../types'
import StyleSheet from '../StyleSheet'
import moduleId from './moduleId'
import {getModuleId} from './moduleId'

const maxRules = 1e10

Expand All @@ -22,6 +22,7 @@ const createGenerateId: CreateGenerateId = (options = {}) => {
let ruleCounter = 0

const generateId: GenerateId = (rule, sheet) => {
const moduleId = getModuleId()
ruleCounter += 1

if (ruleCounter > maxRules) {
Expand Down
7 changes: 6 additions & 1 deletion packages/jss/src/utils/moduleId.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ if (globalThis[ns] == null) globalThis[ns] = 0
// the current version with just one short number and use it for classes generation
// we use a counter. Also it is more accurate, because user can manually reevaluate
// the module.
export default globalThis[ns]++

export const setVersion = (version: number) => {
globalThis[ns] = version
}

export const getModuleId = () => globalThis[ns]++
2 changes: 1 addition & 1 deletion packages/jss/tests/unit/createGenerateId.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const sheetMock = {

describe('Unit: jss - createGenerateId', () => {
beforeEach(() => {
resetSheets()
resetModuleId()
resetSheets()
})

it('should return a function', () => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-github-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const axios = require('axios')
const log = require('npmlog/log')
const {input} = require('@lerna/prompt')

const lerna = require('../lerna')
const lerna = require('../lerna.json')
const {CHANGELOG_FILENAME} = require('./constants')

function getChangelog() {
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {sheets as defaultSheets} from '../packages/jss/src'
import * as moduleIdExports from '../packages/jss/src/utils/moduleId'
import {setVersion} from '../packages/jss/src/utils/moduleId'

export function resetModuleId() {
moduleIdExports.default = 0
setVersion(-1)
}

export function resetSheets(sheets = defaultSheets) {
Expand Down
Loading

0 comments on commit 5c8657a

Please sign in to comment.