Skip to content

Commit 5c8657a

Browse files
Fixing tests for reset moduleId
1 parent 5c2afd9 commit 5c8657a

12 files changed

+777
-1212
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module.exports = {
1414
{
1515
files: ['docs/*.md', 'docs/**/*.md'],
1616
rules: {
17-
'no-console': 'off'
17+
'no-console': 'off',
18+
'import/extensions': 'off'
1819
}
1920
},
2021
{

karma.conf.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const webpack = require('./webpack.config')
2-
const browsers = require('./browsers')
1+
const webpackConfig = require('./webpack.config')
2+
const browsers = require('./browsers.json')
33

44
const isBench = process.env.BENCHMARK === 'true'
55
const useCloud = process.env.USE_CLOUD === 'true'
@@ -10,24 +10,39 @@ const travisBuildNumber = process.env.TRAVIS_BUILD_NUMBER
1010
const travisBuildId = process.env.TRAVIS_BUILD_ID
1111
const travisJobNumber = process.env.TRAVIS_JOB_NUMBER
1212

13+
const getWepackConfig = () => {
14+
delete webpackConfig.entry
15+
delete webpackConfig.output
16+
return webpackConfig
17+
}
18+
1319
module.exports = config => {
1420
config.set({
1521
customLaunchers: browsers,
1622
browsers: ['Chrome'],
17-
frameworks: ['mocha'],
23+
frameworks: ['mocha', 'webpack'],
1824
files: [
1925
'./polyfills.js',
2026
'./packages/*/tests/*.js',
2127
'./packages/*/tests/**/*.js',
2228
'./packages/*/src/**/*.test.js'
2329
],
30+
plugins: [
31+
'karma-webpack',
32+
'karma-mocha',
33+
'karma-sourcemap-loader',
34+
'karma-mocha-reporter',
35+
'karma-coverage',
36+
'karma-chrome-launcher'
37+
],
2438
preprocessors: {
2539
'./polyfills.js': ['webpack', 'sourcemap'],
2640
'./packages/**/*.js': ['webpack', 'sourcemap']
2741
},
28-
webpack,
42+
webpack: getWepackConfig(),
2943
webpackMiddleware: {
30-
stats: 'errors-only'
44+
stats: 'errors-only',
45+
noInfo: true
3146
},
3247
reporters: ['mocha', 'coverage'],
3348
coverageReporter: {

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@
4343
"yarn": ">=1.13"
4444
},
4545
"devDependencies": {
46-
"@babel/core": "^7.2.2",
47-
"@babel/plugin-proposal-class-properties": "^7.3.0",
48-
"@babel/plugin-proposal-object-rest-spread": "^7.3.2",
49-
"@babel/plugin-transform-runtime": "^7.2.0",
50-
"@babel/preset-env": "^7.3.1",
51-
"@babel/preset-flow": "^7.0.0",
52-
"@babel/preset-react": "^7.0.0",
46+
"@babel/core": "^7.14.6",
47+
"@babel/plugin-proposal-class-properties": "^7.14.5",
48+
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
49+
"@babel/plugin-transform-runtime": "^7.14.5",
50+
"@babel/preset-env": "^7.14.7",
51+
"@babel/preset-flow": "^7.14.5",
52+
"@babel/preset-react": "^7.14.5",
5353
"@lerna/prompt": "^3.6.0",
5454
"@rollup/plugin-babel": "^5.2.1",
5555
"@rollup/plugin-commonjs": "^16.0.0",
5656
"@rollup/plugin-node-resolve": "^10.0.0",
5757
"@rollup/plugin-replace": "^2.3.4",
5858
"@types/node": "^14.0.9",
5959
"axios": "^0.18.0",
60-
"babel-loader": "^8.0.4",
61-
"babel-plugin-dev-expression": "^0.2.1",
60+
"babel-loader": "^8.2.2",
61+
"babel-plugin-dev-expression": "^0.2.2",
6262
"camelcase": "^5.0.0",
6363
"chalk": "^2.4.1",
6464
"codecov": "^3.6.5",
@@ -74,19 +74,19 @@
7474
"expect.js": "^0.3.1",
7575
"flow-bin": "^0.138.0",
7676
"json-loader": "^0.5.4",
77-
"karma": "^1.3.0",
78-
"karma-benchmark": "^0.6.0",
77+
"karma": "^6.3.4",
78+
"karma-benchmark": "^1.0.4",
7979
"karma-benchmark-reporter": "^0.1.1",
80-
"karma-browserstack-launcher": "^1.4.0",
81-
"karma-chrome-launcher": "^2.0.0",
82-
"karma-coverage": "^1.1.1",
83-
"karma-mocha": "^1.3.0",
84-
"karma-mocha-reporter": "^2.2.1",
85-
"karma-sourcemap-loader": "^0.3.7",
80+
"karma-browserstack-launcher": "^1.6.0",
81+
"karma-chrome-launcher": "^3.1.0",
82+
"karma-coverage": "^2.0.3",
83+
"karma-mocha": "^2.0.1",
84+
"karma-mocha-reporter": "^2.2.5",
85+
"karma-sourcemap-loader": "^0.3.8",
8686
"karma-webpack": "^5.0.0",
8787
"lerna": "^3.8.0",
8888
"lint-staged": "^3.2.2",
89-
"mocha": "^3.2.0",
89+
"mocha": "^9.0.2",
9090
"npmlog": "^4.1.2",
9191
"pre-commit": "^1.1.3",
9292
"prettier": "^1.13.5",
@@ -100,7 +100,7 @@
100100
"shelljs": "^0.8.2",
101101
"sinon": "4.5.0",
102102
"typescript": "^3.7.0",
103-
"webpack": "^5.42.0",
103+
"webpack": "^5.45.1",
104104
"zen-observable": "^0.6.0"
105105
}
106106
}

packages/jss/.size-snapshot.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
22
"jss.js": {
3-
"bundled": 63771,
4-
"minified": 23307,
5-
"gzipped": 7132
3+
"bundled": 63661,
4+
"minified": 23308,
5+
"gzipped": 7131
66
},
77
"jss.min.js": {
8-
"bundled": 62384,
8+
"bundled": 62274,
99
"minified": 22543,
10-
"gzipped": 6769
10+
"gzipped": 6771
1111
},
1212
"jss.cjs.js": {
13-
"bundled": 59498,
14-
"minified": 26181,
15-
"gzipped": 7202
13+
"bundled": 59388,
14+
"minified": 26209,
15+
"gzipped": 7211
1616
},
1717
"jss.esm.mjs": {
18-
"bundled": 57910,
19-
"minified": 24909,
20-
"gzipped": 7030,
18+
"bundled": 57800,
19+
"minified": 24937,
20+
"gzipped": 7040,
2121
"treeshaked": {
2222
"rollup": {
23-
"code": 20343,
23+
"code": 20345,
2424
"import_statements": 345
2525
},
2626
"webpack": {
27-
"code": 21826
27+
"code": 21827
2828
}
2929
}
3030
}

packages/jss/src/RuleList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22
import createRule from './utils/createRule'
3-
import {StyleRule, KeyframesRule} from './plugins/index'
3+
import {StyleRule, KeyframesRule} from './plugins'
44
import type {
55
RuleListOptions,
66
ToCssOptions,

packages/jss/src/plugins/keyframesRule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import type {
66
JssStyle,
77
RuleOptions,
88
ToCssOptions,
9-
ContainerRule,
109
KeyframesMap,
11-
Plugin
10+
Plugin,
11+
ContainerRule
1212
} from '../types'
1313
import escape from '../utils/escape'
1414

packages/jss/src/utils/createGenerateId.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import warning from 'tiny-warning'
33
import type {Rule} from '../types'
44
import StyleSheet from '../StyleSheet'
5-
import moduleId from './moduleId'
5+
import {getModuleId} from './moduleId'
66

77
const maxRules = 1e10
88

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

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

2728
if (ruleCounter > maxRules) {

packages/jss/src/utils/moduleId.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ if (globalThis[ns] == null) globalThis[ns] = 0
77
// the current version with just one short number and use it for classes generation
88
// we use a counter. Also it is more accurate, because user can manually reevaluate
99
// the module.
10-
export default globalThis[ns]++
10+
11+
export const setVersion = (version: number) => {
12+
globalThis[ns] = version
13+
}
14+
15+
export const getModuleId = () => globalThis[ns]++

packages/jss/tests/unit/createGenerateId.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const sheetMock = {
1313

1414
describe('Unit: jss - createGenerateId', () => {
1515
beforeEach(() => {
16-
resetSheets()
1716
resetModuleId()
17+
resetSheets()
1818
})
1919

2020
it('should return a function', () => {

scripts/create-github-release.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const axios = require('axios')
44
const log = require('npmlog/log')
55
const {input} = require('@lerna/prompt')
66

7-
const lerna = require('../lerna')
7+
const lerna = require('../lerna.json')
88
const {CHANGELOG_FILENAME} = require('./constants')
99

1010
function getChangelog() {

tests/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {sheets as defaultSheets} from '../packages/jss/src'
2-
import * as moduleIdExports from '../packages/jss/src/utils/moduleId'
2+
import {setVersion} from '../packages/jss/src/utils/moduleId'
33

44
export function resetModuleId() {
5-
moduleIdExports.default = 0
5+
setVersion(-1)
66
}
77

88
export function resetSheets(sheets = defaultSheets) {

0 commit comments

Comments
 (0)